Module: Resque

Defined in:
lib/resque/forker.rb,
lib/resque/master.rb,
lib/resque/forker/version.rb

Defined Under Namespace

Classes: Forker, Master

Instance Method Summary collapse

Instance Method Details

#fork!(options = nil) ⇒ Object

Forks workers to take care of the workload.

The workload is an array of queue names, one entry for each worker. For example, if you want to run four workers processing all queues.

Resque.fork! ["*"] * 4

If you want four workers, all of which will be processing imports, but only two processing exports:

Resque.fork! ["import", "import,export"] * 2

Options are:

  • :logger – Which Logger to use (default logger to stdout)

  • :interval – Processing interval (default to 5 seconds)

  • :terminate – Timeout running teardown block (default to 5 seconds)

  • :verbose – Be verbose.

  • :very_verbose – Make :verbose look quiet.

  • :workload – The initial workload.

You can also set these options from the Resque.setup hook.



263
264
265
# File 'lib/resque/forker.rb', line 263

def fork!(options = nil)
  Resque::Forker.new(options).run
end

#infoObject



269
270
271
272
273
# File 'lib/resque/forker.rb', line 269

def info
  hash = info_without_forker
  hash[:script] = ([$0] + ARGV).map { |a| a[/[\s"]/] ? a.inspect : a }.join(" ")
  hash
end

#info_without_forkerObject

Have Resque console show the command/arguments.



268
# File 'lib/resque/forker.rb', line 268

alias :info_without_forker :info

#setup(&block) ⇒ Object

Specify what needs to be done to setup the application. This is the place to load Rails or do anything expensive. For example:

Resque.setup do
  require File.dirname(__FILE__) + "/../config/environment"
  ActiveRecord.disconnect
end


236
237
238
# File 'lib/resque/forker.rb', line 236

def setup(&block)
  block ? (@setup = block) : @setup
end

#teardown(&block) ⇒ Object

Do this before exiting or before reloading.



241
242
243
# File 'lib/resque/forker.rb', line 241

def teardown(&block)
  block ? (@teardown = block) : @teardown
end