Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
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 -
- Job failed (by design) -
- Job failed (exceptional error) -
- Job timed out -
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
#work method, you can actually handle job control by just calling
Timeouts and errors will be called internally by the worker if they occur.