Sidekiq, by design pops a job from Redis and returns it to the Redis queue if an error or a stop action is triggered. This works great if we can guarantee graceful shutdown of Sidekiq workers.
Ideally, this would mean sending the Sidekiq process a kill -15 switch
when we
want to stop it.
However, Sidekiq can't handle other more serious crashes. For example:
- OOM errors
- hardware failure
- network issue
- killing the process with a
kill -9
switch.
- Start the Sidekiq worker:
docker-compose up --build
- Enqueue a job:
docker-compose run worker ruby enqueue.rb
- Wait for Sidekiq to start processing the job
- Trigger a graceful shutdown:
docker-compose stop worker
(this effectively sends akill -15
to the sidekiq worker) - Sidekiq will wait for a while, and then return the job to Redis
- Hit ctlr+c in the terminal that is running
docker-compose up --build
- Restart the worker:
docker-compose up --build
The enqueued job should retry its execution.
- Start the Sidekiq worker:
docker-compose up --build
- Enqueue a job:
docker-compose run worker ruby enqueue.rb
- Wait for Sidekiq to start processing the job
- Trigger a crash of the process:
docker-compose killworker
(this effectively sends akill -9
to the sidekiq worker) - Sidekiq will die immidiately without returning the job to Redis.
- Hit ctlr+c in the terminal that is running
docker-compose up --build
- Restart the worker:
docker-compose up --build
The job is forever lost. :'(