Drew Nichols edited this page May 8, 2015 · 4 revisions

Background processing calls for special treatment for failures.

  • A background job should have limits. Limited resources, limited time, etc.
  • A background job should be able to be: retried, dismissed, acknowledged, rejected.

Sneakers handles this in the following ways.


You can set a job timeout in seconds. This ensures a background job will always take bounded resources.


Sneakers.configure :timeout_job_after => 1


class ProfilingWorker
  include Sneakers::Worker
  from_queue 'downloads',
             :ack => true,
             :timeout_job_after => 1

Job Handling Strategies

When a job needs handling, a Sneakers Handler should do the job. The default one is called a Oneshot handler, because it only tries once.

A handler conforms to:

  • Job is done - #acknowledge
  • Job failed (by design) - #reject
  • Job failed (exceptional error) - #error
  • Job timed out - #timeout

And the Oneshot handler does nothing fancy.

You can implement your own handler (how about ExponentialRetry ?) by filling out the interface and plugging it via configuration like this:

require 'mylib/handlers/exponential_retry'
Sneakers.configure :handler => ExponentialRetry

Handling Jobs

Within your #work method, you can actually handle job control by just calling #ack!, #requeue! or #reject!. Timeouts and errors will be called internally by the worker if they occur.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.