Skip to content

Instantly share code, notes, and snippets.

@tosch
Created February 11, 2011 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tosch/822065 to your computer and use it in GitHub Desktop.
Save tosch/822065 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems' # or better use Bundler
require 'ruote'
require 'ruote/storage/fs_storage'
class WorkerInstance
def initialize(storage = Ruote::FsStorage.new(File.join(File.dirname(__FILE__), 'ruote_work')))
@storage, @worker = storage, Ruote::Worker.new(storage)
end
def run!
trap_signals
@worker.run
end
def stop!
@worker.context.shutdown
end
private
def trap_signals
%w{TERM INT}.each do |signal|
Signal.trap(signal) do # you could trap other signals as well
stop!
exit
end
end
end
end
WorkerInstance.new.run!
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
Daemons.run File.join(File.dirname(__FILE__), 'start_ruote_worker.rb'),
:app_name => "ruote_worker",
:dir_mode => :script,
:dir => '../tmp/pids',
:multiple => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment