Skip to content

Commit

Permalink
mysql: Add mx_update_job2 trigger
Browse files Browse the repository at this point in the history
Remove the -> CANCELLED housekeeping from the mx_update_job trigger. We
no longer set the state to CANCELLED by code.

Instead, add a new trigger, which transitions a job from INQ to
CANCELLED, when the job_cancelled flag ist set.

For Jobs, which are RUNNING, the job_cancelled flag needs to be
handled by the daemon, which kills the job.

By doing it this way, we don't need any code for jobs getting killed in
the LOADED or ASSIGNED states, because these will either transition into
RUNNING or - in very eceptional cases - back into INQ.
  • Loading branch information
donald committed Dec 28, 2023
1 parent f7e2345 commit e334ba7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions mysql/create_trigger.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job
stats_total_real_sec = stats_total_real_sec + NEW.stats_real_sec
WHERE group_id = NEW.group_id;

-- INQ(0) | ASSIGNED(100) | CANCELLING(989) -> CANCELLED(990)
ELSEIF NEW.job_status = 990 AND OLD.job_status IN (0, 100, 989) THEN

SET NEW.date_start = NOW();
SET NEW.date_end = NEW.date_start;

UPDATE mxq_group SET
group_jobs_inq = group_jobs_inq - 1,
group_jobs_cancelled = group_jobs_cancelled + 1
WHERE group_id = NEW.group_id;

-- LOADED(150) | RUNNING(200) -> UNKNOWN(999)
ELSEIF NEW.job_status = 999 AND OLD.job_status IN (150, 200) THEN

Expand Down Expand Up @@ -162,5 +151,17 @@ CREATE TRIGGER mxq_update_job BEFORE UPDATE ON mxq_job
END IF;
END;
|

DROP TRIGGER IF EXISTS mxq_update_job2|
CREATE TRIGGER mxq_update_job2 BEFORE UPDATE ON mxq_job
FOR EACH ROW FOLLOWS mxq_update_job
IF NEW.job_status = 0 AND NEW.job_cancelled THEN
SET NEW.job_status = 990; -- CANCELLED
UPDATE mxq_group SET
group_jobs_inq = group_jobs_inq - 1,
group_jobs_cancelled = group_jobs_cancelled + 1
WHERE group_id = NEW.group_id;
END IF;
|
DELIMITER ;
UNLOCK TABLES;

0 comments on commit e334ba7

Please sign in to comment.