Skip to content
Drew Nichols edited this page May 8, 2015 · 6 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.

Timeouts

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

Sneakers-wide:

Sneakers.configure :timeout_job_after => 1

Worker-wide:

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.