Export job state machine
Export job state machine
stateDiagram-v2
[*] --> Enqueued
Enqueued --> Queued
Queued --> Processing
Processing --> Completed
Processing --> Failed
Failed --> Queued : retry (max 3)
Failed --> Dead : exhausted
Processing --> Cancelled
Queued --> Cancelled
Dead --> [*]
Completed --> [*]
Cancelled --> [*]
state Processing {
[*] --> Running
Running --> Uploading
Running --> Failed : query timeout
Uploading --> Failed : upload error
Uploading --> Notifying
Notifying --> Completed
end
If a worker crashes without updating the job status, the lease mechanism recovers:
1. Worker acquires lease (UPDATE ... lease_expiry = now() + 5m)
2. Worker crashes
3. No other worker can acquire this job while lease is valid
4. After lease expiry, polling query picks it up:
SELECT * FROM export_jobs
WHERE status = 'processing' AND lease_expiry < now()
5. Status is reset to 'queued'; retry_count stays unchanged
6. Another worker processes it
Was this page helpful?
Thanks for your feedback!