Skip to content

Instantly share code, notes, and snippets.

@Erol
Created June 17, 2021 10:37
Show Gist options
  • Save Erol/e58257ce67d0fa8c795f7b1c33da750c to your computer and use it in GitHub Desktop.
Save Erol/e58257ce67d0fa8c795f7b1c33da750c to your computer and use it in GitHub Desktop.
class TestWorker < ApplicationWorker
sidekiq_options retry: false, queue: 'test'
def perform
Sidekiq::Batch.new.tap do |batch|
batch.on(:death, 'TestWorker#on_death')
batch.jobs do
SampleWorker.perform_async
end
end
end
def on_death(status, options)
logger.info('---DEATH---')
logger.info(status)
logger.info(options)
end
end
class SampleWorker < ApplicationWorker
sidekiq_options retry: false, queue: 'test'
def perform
meh # Intentionally fail
end
end
Log Output:
2021-06-17T10:34:31.782Z pid=94855 tid=55p7 class=Sidekiq::Batch::Callback jid=d6ba7f484f73bacb16ea12a4 INFO: start
2021-06-17T10:34:31.785Z pid=94855 tid=55p7 class=Sidekiq::Batch::Callback jid=d6ba7f484f73bacb16ea12a4 elapsed=0.003 INFO: done
2021-06-17T10:34:31.786Z pid=94855 tid=55p7 class=Sidekiq::Batch::Callback jid=48eb50dcbf4a0b7c07198601 INFO: start
2021-06-17T10:34:31.788Z pid=94855 tid=55p7 class=Sidekiq::Batch::Callback jid=48eb50dcbf4a0b7c07198601 INFO: ---DEATH---
2021-06-17T10:34:31.788Z pid=94855 tid=55p7 class=Sidekiq::Batch::Callback jid=48eb50dcbf4a0b7c07198601 INFO: #<Sidekiq::Batch::Status:0x00007f8da90a58a0>
2021-06-17T10:34:31.788Z pid=94855 tid=55p7 class=Sidekiq::Batch::Callback jid=48eb50dcbf4a0b7c07198601 INFO: {}
2021-06-17T10:34:31.788Z pid=94855 tid=55p7 class=Sidekiq::Batch::Callback jid=48eb50dcbf4a0b7c07198601 elapsed=0.002 INFO: done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment