简体   繁体   中英

Shedlock and temporary stop task(s)?

When running several scheduled tasks on multiple servers, Shedlock seems great, but sometimes, we need to halt some of the tasks for a short or long period too. Of course, it is possible to control each task with additional properties/flags, but my suggestion is to use Shedlock for this too, and introduce a logical "node/server" for the task we wish to stop, and update the row in shedlock-table with a lock to this node, and set a lockedAt time in the future, and a lockUntil to future + 1 second (so longer than maxRunning is not triggered). Then it will start again automatically, or we can go in and move the time further into the future if needed.

Any thoughts on this kind of use for Shedlock... smart or bad practice? It is still used for locking, just locking the job to a logical fake server.

It is possible to (mis)use ShedLock for this. The update you are looking for can look like this:

update shedlock set lock_until = :future, locked_at = now(), locked_by = "manual" where 
      name = :name and lock_until < now()

The important part is the condition lock_until < now() which prevents meddling with an existing lock for a running task. You do not have to set locked_by since it's mostly ignored by the library. It's just better to set it just in case someone else wonders why the tasks are not being executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM