rq / rq-scheduler

A lightweight library that adds job scheduling capabilities to RQ (Redis Queue)
MIT License
1.45k stars 229 forks source link

Use a transaction when enqueuing a job to ensure atomicity #223

Open marianstefi20 opened 4 years ago

marianstefi20 commented 4 years ago

Suppose the scheduler receives a SIGKILL. If this happens between zrem and zadd in enqueue_job() the repeatable or cron jobs might stop working properly altogether. This is because the job is first consumed from Redis and later added in the sorted set with a score that's the future time at which it will run.

To solve this, I propose using a transaction in enqueue_job. This would assure the atomicity of the sequence of operations.

selwin commented 4 years ago

Sorry for the late reply, I'd like to get this merged in if you could just address my comment here: https://github.com/rq/rq-scheduler/pull/223#discussion_r414228561