Skip to content

Commit

Permalink
sql: Add mx_update_job2 trigger
Browse files Browse the repository at this point in the history
This commit removes the -> `CANCELLED` housekeeping from the
`mx_update_job` trigger as we no longer set the state to `CANCELLED` by
code.

Instead, a new trigger is added, which transitions a job from `INQ` to
`CANCELLED` when the `job_cancelled` flag is set.

For jobs that are `RUNNING`, the `job_cancelled` flag needs to be
handled by the daemon, which kills the job. Note that the job will
transition into `KILLED` not into `CANCELLED`.

This approach eliminates the need for any code for jobs getting killed
in the `LOADED` or `ASSIGNED` states, as these will either transition
into `RUNNING` or - in very exceptional cases - back into INQ.
  • Loading branch information
donald committed Dec 29, 2023
1 parent c22b537 commit 22aadf3
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 22aadf3

Please sign in to comment.