1
0
Fork 0
mirror of https://github.com/deanpcmad/sidekiq-limit_fetch.git synced 2022-11-09 13:54:36 -05:00
deanpcmad--sidekiq-limit_fetch/demo/Rakefile
dany1468 74f8d281fb Fix demo app
- Remove unnecessary gems
- Fix Sidekiq Web URL
2016-12-09 18:11:56 +09:00

99 lines
1.9 KiB
Ruby

require File.expand_path('../config/application', __FILE__)
Demo::Application.load_tasks
namespace :demo do
task limit: :environment do
puts '=> Creating sidekiq tasks'
100.times do
SlowWorker.perform_async
FastWorker.perform_async
end
run_sidekiq_monitoring
run_sidekiq_workers config: <<-YAML
:verbose: false
:concurrency: 4
:queues:
- slow
- fast
:limits:
slow: 1
YAML
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)
whitespace_offset = config[/\A */].size
config.gsub! /^ {#{whitespace_offset}}/, ''
puts "=> Use sidekiq config:\n#{config}"
File.write 'config/sidekiq.yml', config
yield
ensure
FileUtils.rm 'config/sidekiq.yml'
end
def run_sidekiq_monitoring
require 'sidekiq/web'
Thread.new do
Rack::Server.start app: Sidekiq::Web, Port: 3000
end
sleep 1
Launchy.open 'http://127.0.0.1:3000/busy?poll=true'
end
def run_sidekiq_workers(options)
require 'sidekiq/cli'
cli = Sidekiq::CLI.instance
%w(validate! boot_system).each do |stub|
cli.define_singleton_method(stub) {}
end
with_sidekiq_config options[:config] do
cli.send :setup_options, []
end
cli.run
end
end