If the queue itself crashes, rebuild it from a log
Your queue lives in memory. If its process dies, every task in it is gone, and that's worse than any one worker crashing.
The usual answer is a log: before the queue changes anything, it appends a line describing the change to a file, and flushes it to disk. Enqueue, reserve, ack and fail each write one line. After a crash, the new process reads the log from the start and applies each line in order, which rebuilds the state.
One choice to make on purpose: what about tasks that were reserved when the queue crashed? Their leases lived in memory, and the clock has moved on since. The safe choice is to treat every one of them as waiting again. If the worker was still running, it'll do the work a second time, which is fine, because the work is idempotent. If the worker died with the queue, the task would otherwise be lost.
A log grows forever. So every so often, the queue writes a snapshot of its whole state and starts a new log after it. A restart reads the newest snapshot, then only the log since it.
Real systems often hand this whole problem to a database or a message broker. Saying so is fine. But know what they do underneath, because "it's in the database" invites the next question: what happens to a reserved task when the database fails over?
The function replay in the editor rebuilds each task's state from the log. Write it, so it applies every event in order and then sends every task still reserved back to waiting.