Skip to content

Instantly share code, notes, and snippets.

@lwe
Created November 20, 2012 15:33
Show Gist options
  • Save lwe/4118637 to your computer and use it in GitHub Desktop.
Save lwe/4118637 to your computer and use it in GitHub Desktop.
require 'sidekiq'
require 'sidekiq/manager'
require 'sidekiq/scheduled'
class SidekiqService
attr_reader :options, :manager
def initialize(options = {})
@options = options
@manager = Sidekiq::Manager.new(options.reverse_merge(concurrency: 50, queues: %w{default}))
@poller = Sidekiq::Scheduled::Poller.new
end
def start
manager.async.start
poller.async.poll(true)
end
def stop
poller.async.terminate if poller.alive?
manager.async.stop(shutdown: true, timeout: options[:timeout] || 100)
manager.wait(:shutdown)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment