Commit 72a90997 authored by Leo Gordon's avatar Leo Gordon
Browse files

experimental: do the job counting immediately by SQL triggers rather than periodically by Perl code

parent 0f477f14
CREATE TRIGGER add_job AFTER INSERT ON job
FOR EACH ROW
UPDATE analysis_stats SET
total_job_count = total_job_count + 1,
unclaimed_job_count = unclaimed_job_count + (CASE NEW.status WHEN 'READY' THEN 1 ELSE 0 END),
done_job_count = done_job_count + (CASE NEW.status WHEN 'DONE' THEN 1 WHEN 'PASSED_ON' THEN 1 ELSE 0 END),
failed_job_count = failed_job_count + (CASE NEW.status WHEN 'FAILED' THEN 1 ELSE 0 END),
status = (CASE WHEN status!='BLOCKED' THEN 'LOADING' ELSE 'BLOCKED' END)
WHERE analysis_id = NEW.analysis_id;
CREATE TRIGGER delete_job AFTER DELETE ON job
FOR EACH ROW
UPDATE analysis_stats SET
total_job_count = total_job_count - 1,
unclaimed_job_count = unclaimed_job_count - (CASE OLD.status WHEN 'READY' THEN 1 ELSE 0 END),
done_job_count = done_job_count - (CASE OLD.status WHEN 'DONE' THEN 1 WHEN 'PASSED_ON' THEN 1 ELSE 0 END),
failed_job_count = failed_job_count - (CASE OLD.status WHEN 'FAILED' THEN 1 ELSE 0 END)
WHERE analysis_id = OLD.analysis_id;
CREATE TRIGGER update_job AFTER UPDATE ON job
FOR EACH ROW
UPDATE analysis_stats SET
unclaimed_job_count = unclaimed_job_count + (CASE NEW.status WHEN 'READY' THEN 1 WHEN 'CLAIMED' THEN -1 ELSE 0 END),
done_job_count = done_job_count + (CASE NEW.status WHEN 'DONE' THEN 1 WHEN 'PASSED_ON' THEN 1 ELSE 0 END),
failed_job_count = failed_job_count + (CASE NEW.status WHEN 'FAILED' THEN 1 ELSE 0 END)
WHERE analysis_id = NEW.analysis_id;
CREATE TRIGGER add_job AFTER INSERT ON job
FOR EACH ROW
BEGIN
UPDATE analysis_stats SET
total_job_count = total_job_count + 1,
unclaimed_job_count = unclaimed_job_count + (CASE NEW.status WHEN 'READY' THEN 1 ELSE 0 END),
done_job_count = done_job_count + (CASE NEW.status WHEN 'DONE' THEN 1 WHEN 'PASSED_ON' THEN 1 ELSE 0 END),
failed_job_count = failed_job_count + (CASE NEW.status WHEN 'FAILED' THEN 1 ELSE 0 END),
status = (CASE WHEN status!='BLOCKED' THEN 'LOADING' ELSE 'BLOCKED' END)
WHERE analysis_id = NEW.analysis_id;
END;
CREATE TRIGGER delete_job AFTER DELETE ON job
FOR EACH ROW
BEGIN
UPDATE analysis_stats SET
total_job_count = total_job_count - 1,
unclaimed_job_count = unclaimed_job_count - (CASE OLD.status WHEN 'READY' THEN 1 ELSE 0 END),
done_job_count = done_job_count - (CASE OLD.status WHEN 'DONE' THEN 1 WHEN 'PASSED_ON' THEN 1 ELSE 0 END),
failed_job_count = failed_job_count - (CASE OLD.status WHEN 'FAILED' THEN 1 ELSE 0 END)
WHERE analysis_id = OLD.analysis_id;
END;
CREATE TRIGGER update_job AFTER UPDATE ON job
FOR EACH ROW
BEGIN
UPDATE analysis_stats SET
unclaimed_job_count = unclaimed_job_count + (CASE NEW.status WHEN 'READY' THEN 1 WHEN 'CLAIMED' THEN -1 ELSE 0 END),
done_job_count = done_job_count + (CASE NEW.status WHEN 'DONE' THEN 1 WHEN 'PASSED_ON' THEN 1 ELSE 0 END),
failed_job_count = failed_job_count + (CASE NEW.status WHEN 'FAILED' THEN 1 ELSE 0 END)
WHERE analysis_id = NEW.analysis_id;
END;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment