Commit 8d873af3 authored by Leo Gordon's avatar Leo Gordon
Browse files

proper counting of semaphored jobs by triggers and in constructor

parent 830a7229
......@@ -105,7 +105,7 @@ sub CreateNewJob {
my $dba = $analysis->adaptor->db;
my $dbc = $dba->dbc;
my $insertion_method = ($dbc->driver eq 'sqlite') ? 'INSERT OR IGNORE' : 'INSERT IGNORE';
my $status = ($semaphore_count>0) ? 'SEMAPHORED' : 'READY';
my $job_status = ($semaphore_count>0) ? 'SEMAPHORED' : 'READY';
my $analysis_id = $analysis->dbID();
my $sql = qq{$insertion_method INTO job
......@@ -113,7 +113,7 @@ sub CreateNewJob {
VALUES (?,?,?,?,?,?)};
my $sth = $dbc->prepare($sql);
my @values = ($input_id, $prev_job_id, $analysis_id, $status, $semaphore_count, $semaphored_job_id);
my @values = ($input_id, $prev_job_id, $analysis_id, $job_status, $semaphore_count, $semaphored_job_id);
my $return_code = $sth->execute(@values)
# using $return_code in boolean context allows to skip the value '0E0' ('no rows affected') that Perl treats as zero but regards as true:
......@@ -134,8 +134,10 @@ sub CreateNewJob {
UPDATE analysis_stats
SET total_job_count=total_job_count+1
}
.(($status eq 'READY') ? " ,ready_job_count=ready_job_count+1 " : '')
.qq{
.(($job_status eq 'READY')
? " ,ready_job_count=ready_job_count+1 "
: " ,semaphored_job_count=semaphored_job_count+1 "
).qq{
,status = (CASE WHEN status!='BLOCKED' THEN 'LOADING' ELSE 'BLOCKED' END)
WHERE analysis_id=$analysis_id
});
......
......@@ -2,21 +2,23 @@
CREATE TRIGGER add_job AFTER INSERT ON job
FOR EACH ROW
UPDATE analysis_stats SET
total_job_count = total_job_count + 1,
ready_job_count = ready_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)
total_job_count = total_job_count + 1,
semaphored_job_count = semaphored_job_count + (CASE NEW.status WHEN 'SEMAPHORED' THEN 1 ELSE 0 END),
ready_job_count = ready_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,
ready_job_count = ready_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)
total_job_count = total_job_count - 1,
semaphored_job_count = semaphored_job_count - (CASE OLD.status WHEN 'SEMAPHORED' THEN 1 ELSE 0 END),
ready_job_count = ready_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;
DELIMITER $$
......@@ -26,16 +28,18 @@ FOR EACH ROW
CASE WHEN (OLD.status<>NEW.status OR OLD.analysis_id<>NEW.analysis_id) THEN
BEGIN
UPDATE analysis_stats SET
total_job_count = total_job_count - 1,
ready_job_count = ready_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)
total_job_count = total_job_count - 1,
semaphored_job_count = semaphored_job_count - (CASE OLD.status WHEN 'SEMAPHORED' THEN 1 ELSE 0 END),
ready_job_count = ready_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;
UPDATE analysis_stats SET
total_job_count = total_job_count + 1,
ready_job_count = ready_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)
total_job_count = total_job_count + 1,
semaphored_job_count = semaphored_job_count + (CASE NEW.status WHEN 'SEMAPHORED' THEN 1 ELSE 0 END),
ready_job_count = ready_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)
WHERE analysis_id = NEW.analysis_id;
END;
END CASE$$
......
......@@ -3,10 +3,11 @@ CREATE TRIGGER add_job AFTER INSERT ON job
FOR EACH ROW
BEGIN
UPDATE analysis_stats SET
total_job_count = total_job_count + 1,
ready_job_count = ready_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),
total_job_count = total_job_count + 1,
semaphored_job_count = semaphored_job_count + (CASE NEW.status WHEN 'SEMAPHORED' THEN 1 ELSE 0 END),
ready_job_count = ready_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;
......@@ -15,10 +16,11 @@ CREATE TRIGGER delete_job AFTER DELETE ON job
FOR EACH ROW
BEGIN
UPDATE analysis_stats SET
total_job_count = total_job_count - 1,
ready_job_count = ready_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)
total_job_count = total_job_count - 1,
semaphored_job_count = semaphored_job_count - (CASE OLD.status WHEN 'SEMAPHORED' THEN 1 ELSE 0 END),
ready_job_count = ready_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;
......@@ -26,16 +28,19 @@ CREATE TRIGGER update_job AFTER UPDATE ON job
FOR EACH ROW
BEGIN
UPDATE analysis_stats SET
total_job_count = total_job_count - 1,
ready_job_count = ready_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)
total_job_count = total_job_count - 1,
semaphored_job_count = semaphored_job_count - (CASE OLD.status WHEN 'SEMAPHORED' THEN 1 ELSE 0 END),
ready_job_count = ready_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;
UPDATE analysis_stats SET
total_job_count = total_job_count + 1,
ready_job_count = ready_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)
total_job_count = total_job_count + 1,
semaphored_job_count = semaphored_job_count + (CASE NEW.status WHEN 'SEMAPHORED' THEN 1 ELSE 0 END),
ready_job_count = ready_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)
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