collectiveidea/delayed_job — Issue #327: feedback needed: retrieve # of attempts from within MyJob#perform ?
Author: enrico
Created: 2012-01-03 17:39:37+00:00
State: open

I would like to be able to define some logic in my job that depends on the # of attempts this job has run in the past.

For example I could set a system-wide max # of attempts to 25, but decide to override it in a specific job model by simply deciding to abandon the job by returning without throwing an exception if the number of attempts is, say > 10...

I am not aware of a way to retrieve the current # of attempts. If there is one, could anyone please point me to it?

Otherwise, I was wondering whether something like this could work and be acceptable to implement (tests would follow, of course...) Since I was at it, I decided to pass a hash to perform which also includes priority, queue and locked_by.

in invoke_job (lib/delayed/backend/base.rb, lines 93,99

```
hook :before
arg_count = payload_object.method(:perform).arity rescue 0
arg_count == 0 ? payload_object.perform : payload_object.perform({:attempts => attempts,
:priority => priority,
:queue => queue,
:locked_by => locked_by})
hook :success
```