Open
Description
Hi. We have a lot of tasks in ENQUEUED status but they executed and jobs well done.
I think we have small race condition at middleware callbacks:
Scheduler
emit before_enqueueScheduler
publish task to queueWorker
got task from queueWorker
emit before processing (update task status=RUNNING)Worker
done taskWorker
emit after processing. (update task status=DONE)Scheduler
emit afer_enqueue (update task status=ENQUEUED)
You can see different order for Create
and Update
logs. But last log is Update
. Do not worry, message logged before SQL operation and this is not equal reflection of SQL updates.
So, i want make a PR to fix that. I see two solutions for that case:
- Optimistic locks: check row version at update and ignore if it changed (this require schema update)
- Do not allow change status from DONE/RUNNING to ENQUEUED. Check status when update. (control state flow)
@amureki what do you think about that?