lib/resque/worker.rb
def work(interval = 5, &block)
      interval = Integer(interval)
      $0 = "resque: Starting"
      startup

      loop do
        break if shutdown?

        if !paused?
          procline "Waiting for #{@queues.join(',')}"
        end

        if !paused? && job = reserve(interval)
          log "got: #{job.inspect}"
          job.worker = self
          run_hook :before_fork, job
          working_on job

          if @child = fork
            srand # Reseeding
            procline "Forked #{@child} at #{Time.now.to_i}"
            Process.wait(@child)
          else
            procline "Processing #{job.queue} since #{Time.now.to_i}"
            perform(job, &block)
            exit! unless @cant_fork
          end

          done_working
          @child = nil

          run_hook :after_perform, self
        else
          break if interval.zero? # for testing
          if paused?
            procline "Paused"
            sleep interval
          end
        end
      end

    ensure
      unregister_worker
    end
# This is the main workhorse method. Called on a Worker instance,
# it begins the worker life cycle.
#
# The following events occur during a worker's life cycle:
#
# 1. Startup:   Signals are registered, dead workers are pruned,
#               and this worker is registered.
# 2. Work loop: Jobs are pulled from a queue and processed.
# 3. Teardown:  This worker is unregistered.
#
# Can be passed an integer representing the polling frequency.
# The default is 5 seconds, but for a semi-active site you may
# want to use a smaller value.
#
# Also accepts a block which will be passed the job as soon as it
# has completed processing. Useful for testing.
This is the main workhorse method. Called on a Worker instance,
it begins the worker life cycle.

The following events occur during a worker's life cycle.

1. Startup:   Signals are registered, dead workers are pruned,
and this worker is registered.
2. Work loop: Jobs are pulled from a queue and processed.
3. Teardown:  This worker is unregistered.

Can be passed an integer representing the polling frequency.
The default is 5 seconds, but for a semi-active site you may
want to use a smaller value.

Also accepts a block which will be passed the job as soon as it
has completed processing. Useful for testing.
This is the main workhorse method . Called on a Worker instance it begins the worker life cycle . The following events occur during a worker ' s life cycle . 1 . Startup : Signals are registered dead workers are pruned and this worker is registered . 2 . Work loop : Jobs are pulled from a queue and processed . 3 . Teardown : This worker is unregistered . Can be passed an integer representing the polling frequency . The default is 5 seconds but for a semi - active site you may want to use a smaller value . Also accepts a block which will be passed the job as soon as it has completed processing . Useful for testing .
def work(interval = 5, &block)
      interval = Integer(interval)
      $0 = "resque: Starting"
      startup
      loop do
        break if shutdown?
        if !paused?
          procline "Waiting for #{@queues.join(',')}"
        end
        if !paused? && job = reserve(interval)
          log "got: #{job.inspect}"
          job.worker = self
          run_hook :before_fork, job
          working_on job
          if @child = fork
            srand 
            procline "Forked #{@child} at #{Time.now.to_i}"
            Process.wait(@child)
          else
            procline "Processing #{job.queue} since #{Time.now.to_i}"
            perform(job, &block)
            exit! unless @cant_fork
          end
          done_working
          @child = nil
          run_hook :after_perform, self
        else
          break if interval.zero? 
          if paused?
            procline "Paused"
            sleep interval
          end
        end
      end
    ensure
      unregister_worker
    end
def work ( interval = 5 , & block ) interval = Integer ( interval ) $0 = "resque: Starting" startup loop do break if shutdown? if ! paused? procline "Waiting for #{@queues.join(',')}" end if ! paused? && job = reserve ( interval ) log "got: #{job.inspect}" job . worker = self run_hook :before_fork , job working_on job if @child = fork srand procline "Forked #{@child} at #{Time.now.to_i}" Process . wait ( @child ) else procline "Processing #{job.queue} since #{Time.now.to_i}" perform ( job , & block ) exit! unless @cant_fork end done_working @child = nil run_hook :after_perform , self else break if interval . zero? if paused? procline "Paused" sleep interval end end end ensure unregister_worker end
This is the main workhorse method.
This is the main workhorse method .
# Reseeding # for testing
interval
block