mirror of
https://github.com/deanpcmad/sidekiq-limit_fetch.git
synced 2022-11-09 13:54:36 -05:00
Add demo tasks for blocking and advanced blocking
This commit is contained in:
parent
160f91792e
commit
22d3cac2c8
4 changed files with 65 additions and 2 deletions
|
@ -22,6 +22,45 @@ namespace :demo do
|
||||||
YAML
|
YAML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
task blocking: :environment do
|
||||||
|
puts '=> Creating sidekiq tasks'
|
||||||
|
|
||||||
|
AWorker.perform_async
|
||||||
|
BWorker.perform_async
|
||||||
|
CWorker.perform_async
|
||||||
|
|
||||||
|
run_sidekiq_monitoring
|
||||||
|
run_sidekiq_workers config: <<-YAML
|
||||||
|
:verbose: false
|
||||||
|
:concurrency: 4
|
||||||
|
:queues:
|
||||||
|
- a
|
||||||
|
- b
|
||||||
|
- c
|
||||||
|
:blocking:
|
||||||
|
- a
|
||||||
|
YAML
|
||||||
|
end
|
||||||
|
|
||||||
|
task advanced_blocking: :environment do
|
||||||
|
puts '=> Creating sidekiq tasks'
|
||||||
|
|
||||||
|
AWorker.perform_async
|
||||||
|
BWorker.perform_async
|
||||||
|
CWorker.perform_async
|
||||||
|
|
||||||
|
run_sidekiq_monitoring
|
||||||
|
run_sidekiq_workers config: <<-YAML
|
||||||
|
:verbose: false
|
||||||
|
:concurrency: 4
|
||||||
|
:queues:
|
||||||
|
- a
|
||||||
|
- b
|
||||||
|
- c
|
||||||
|
:blocking:
|
||||||
|
- [a, b]
|
||||||
|
YAML
|
||||||
|
end
|
||||||
def with_sidekiq_config(config)
|
def with_sidekiq_config(config)
|
||||||
whitespace_offset = config[/\A */].size
|
whitespace_offset = config[/\A */].size
|
||||||
config.gsub! /^ {#{whitespace_offset}}/, ''
|
config.gsub! /^ {#{whitespace_offset}}/, ''
|
||||||
|
@ -51,8 +90,7 @@ namespace :demo do
|
||||||
end
|
end
|
||||||
|
|
||||||
with_sidekiq_config options[:config] do
|
with_sidekiq_config options[:config] do
|
||||||
config = cli.send :parse_config, 'config/sidekiq.yml'
|
cli.send :setup_options, []
|
||||||
Sidekiq.options.merge! config
|
|
||||||
end
|
end
|
||||||
|
|
||||||
cli.run
|
cli.run
|
||||||
|
|
8
demo/app/workers/a_worker.rb
Normal file
8
demo/app/workers/a_worker.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class AWorker
|
||||||
|
include Sidekiq::Worker
|
||||||
|
sidekiq_options queue: :a
|
||||||
|
|
||||||
|
def perform
|
||||||
|
sleep 10
|
||||||
|
end
|
||||||
|
end
|
8
demo/app/workers/b_worker.rb
Normal file
8
demo/app/workers/b_worker.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class BWorker
|
||||||
|
include Sidekiq::Worker
|
||||||
|
sidekiq_options queue: :b
|
||||||
|
|
||||||
|
def perform
|
||||||
|
sleep 10
|
||||||
|
end
|
||||||
|
end
|
9
demo/app/workers/c_worker.rb
Normal file
9
demo/app/workers/c_worker.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
class CWorker
|
||||||
|
include Sidekiq::Worker
|
||||||
|
sidekiq_options queue: :c
|
||||||
|
|
||||||
|
def perform
|
||||||
|
sleep 10
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue