Skip to main content

Practice ยท 2 of 2

Die gracefully, lose nothing

Implement graceful_shutdown(worker, sigterm=True, sigint=False) โ€” the worker has running (bool), in_flight (int count), drained (bool), requeued (list): - sigterm=False, sigint=False simulates SIGKILL: return the worker untouched (nothing graceful happens) - otherwise: running = False (stop accepting), any in-flight work is appended to requeued (durably re-queueable, thanks to idempotent jobs) and in_flight = 0, then drained = True - return the worker The invariant: after a graceful shutdown, in_flight == 0 AND every unit of work is accounted for in requeued.

Difficulty: advanced

Back to lesson: Practice: Systems Drills