Class: Rage::Deferred::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/deferred/metadata.rb

Overview

Provides metadata about the current deferred task execution.

Class Method Summary collapse

Class Method Details

.attemptsInteger

Returns the current attempt number.

Returns:

  • (Integer)

    the current attempt number (1 for the first run)



10
11
12
# File 'lib/rage/deferred/metadata.rb', line 10

def attempts
  Rage::Deferred::Context.get_attempts(context).to_i + 1
end

.retriesInteger

Returns the number of retries that have occurred for the current task.

Returns:

  • (Integer)

    the number of retries (0 on first run, 1+ on retries)



16
17
18
# File 'lib/rage/deferred/metadata.rb', line 16

def retries
  attempts - 1
end

.retrying?Boolean

Checks whether this is a retry execution.

Returns:

  • (Boolean)

    true if this is a retry, false if this is the first run



22
23
24
# File 'lib/rage/deferred/metadata.rb', line 22

def retrying?
  attempts > 1
end

.will_retry?Boolean

Checks whether the task will be retried if the current execution fails.

Returns:

  • (Boolean)

    true if a failure will schedule another attempt, false otherwise



28
29
30
31
# File 'lib/rage/deferred/metadata.rb', line 28

def will_retry?
  task = Rage::Deferred::Context.get_task(context)
  !!task.__next_retry_in(attempts, nil)
end

.will_retry_inNumeric?

Returns the number of seconds until the next retry, or nil if no retry will occur. The result is memoized per attempt so that the value reported here matches what the queue uses to schedule the retry.

Returns:

  • (Numeric, nil)

    retry delay in seconds, or nil if the task won't be retried



36
37
38
39
# File 'lib/rage/deferred/metadata.rb', line 36

def will_retry_in
  task = Rage::Deferred::Context.get_task(context)
  task.__next_retry_in(attempts, nil)
end