Last active
March 26, 2017 22:04
-
-
Save steveburkett/97c33832913aeccfff346927a848b787 to your computer and use it in GitHub Desktop.
sidekiq pro batch testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DwTestJob1 | |
include Sidekiq::Worker | |
sidekiq_options queue: :default, retry: false | |
def perform(opts={}) | |
puts('Starting Job1') | |
sleep(1.minute) | |
puts('Ending Job1') | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DwTestJob2 | |
include Sidekiq::Worker | |
sidekiq_options queue: :default, retry: false | |
def perform(opts={}) | |
puts('Starting Job2') | |
sleep(1.minute) | |
puts('Ending Job2') | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#inspired by https://github.com/mperham/sidekiq/wiki/Really-Complex-Workflows-with-Batches | |
class DwTestWorkflow | |
include Sidekiq::Worker | |
def perform(client_urn) | |
puts "Dw Test workflow for #{client_urn} is about to be started" | |
overall = Sidekiq::Batch.new | |
overall.on(:success, 'DwTestWorkflow#all_done', client_urn: client_urn) | |
overall.description = "Dw Test workflow (master) for #{client_urn}" | |
overall.jobs do | |
level1 = Sidekiq::Batch.new | |
level1.description = "Dw Test workflow (level1) for #{client_urn}" | |
level1.on(:success, 'DwTestWorkflow#level2', client_urn: client_urn) | |
level1.jobs do | |
#here, enqueue all level 1 jobs | |
puts "Dw Test workflow-adding jobs to level1 processing" | |
DwTestJob1.perform_async(client_urn) | |
end | |
end | |
puts "Dw Test workflow for #{client_urn} has started!" | |
end | |
def level2(status, options) | |
puts "Dw Test workflow-entering level2 processing" | |
urn = options['client_urn'] | |
overall = Sidekiq::Batch.new(status.parent_bid) | |
overall.description = "Dw Test workflow (continued) for #{urn}" | |
overall.jobs do | |
level2 = Sidekiq::Batch.new | |
level2.description = "Dw Test workflow level2 for #{urn}" | |
level2.jobs do | |
puts "Dw Test workflow-adding jobs to level2 processing" | |
#here, enqueue all level 2 jobs | |
DwTestJob2.perform_async(urn) | |
end | |
end | |
puts "Dw Test workflow-leaving level2 processing" | |
end | |
def all_done(status, options) | |
urn = options['client_urn'] | |
puts "Dw Test workflow for #{urn} has finished!" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#inspired by http://blog.animascodelabs.com/2015/12/28/workflows-with-sidekiq-batches/ | |
class DwTestWorkflow | |
include Sidekiq::Worker | |
def perform(client_urn) | |
puts "Dw Test workflow for #{client_urn} is about to be started" | |
overall = Sidekiq::Batch.new | |
overall.on(:success, 'DwTestWorkflow#all_done', client_urn: client_urn) | |
overall.description = "Dw Test workflow (master) for #{client_urn}" | |
overall.jobs do | |
level1 = Sidekiq::Batch.new | |
level1.description = "Dw Test workflow (level1) for #{client_urn}" | |
level1.on(:success, 'DwTestWorkflow#level2', client_urn: client_urn) | |
level1.jobs do | |
#here, enqueue all level 1 jobs | |
puts "Dw Test workflow-adding jobs to level1 processing" | |
DwTestJob1.perform_async(client_urn) | |
end | |
end | |
puts "Dw Test workflow for #{client_urn} has started!" | |
end | |
def level2(status, options) | |
puts "Dw Test workflow-entering level2 processing" | |
urn = options['client_urn'] | |
overall = Sidekiq::Batch.new(status.parent_bid) | |
overall.description = "Dw Test workflow (continued) for #{urn}" | |
overall.jobs do | |
puts "Dw Test workflow-adding jobs to level2 processing" | |
#here, enqueue all level 2 jobs | |
DwTestJob2.perform_async(urn) | |
end | |
puts "Dw Test workflow-leaving level2 processing" | |
end | |
def all_done(status, options) | |
urn = options['client_urn'] | |
puts "Dw Test workflow for #{urn} has finished!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment