Module: Postburner::Properties
- Extended by:
- ActiveSupport::Concern
- Included in:
- Job
- Defined in:
- app/concerns/postburner/properties.rb
Overview
Queue properties module for Postburner::Job classes.
Provides DSL methods for configuring queue behavior (name, priority, TTR, retries). Defines configurable properties for job queue management.
Retry Behavior
By default, Postburner::Job does NOT retry failed jobs. When a job raises an exception, it is buried in Beanstalkd for inspection. This differs from default ActiveJob behavior (5 retries with 2^n second backoff, ~31s total).
Use max_retries to enable automatic retries:
class MyJob < Postburner::Job
max_retries 5 # Retry up to 5 times with exponential backoff (1s, 2s, 4s, 8s, 16s)
end
The default retry_delay is exponential backoff (2^n seconds), matching Postburner’s default ActiveJob behavior. Override with a fixed delay or custom proc:
retry_delay 10 # Fixed 10 second delay between retries
# Match ActiveJob's :exponentially_longer (polynomial: (n+1)^4 + 2)
retry_delay ->(n) { ((n + 1) ** 4) + 2 } # 3s, 18s, 83s, 258s, 627s
Instance Method Summary collapse
-
#priority ⇒ Integer?
(also: #pri)
Returns the priority for this job instance.
-
#queue_name ⇒ String
Returns the queue name for this job instance.
-
#retry_delay_for_attempt(attempt) ⇒ Integer
Calculates the retry delay for the given attempt.
-
#should_retry? ⇒ Boolean
Checks if this job should retry after a failure.
-
#ttr ⇒ Integer?
Returns the TTR (time-to-run) for this job instance.
-
#tube_name ⇒ String
(also: #expanded_tube_name)
Returns the full Beanstalkd tube name with environment prefix.
Instance Method Details
#priority ⇒ Integer? Also known as: pri
Returns the priority for this job instance.
Checks instance-level override first, then falls back to class-level configuration.
238 239 240 |
# File 'app/concerns/postburner/properties.rb', line 238 def priority @priority || self.class.priority end |
#queue_name ⇒ String
Returns the queue name for this job instance.
Checks instance-level override first, then falls back to class-level configuration.
204 205 206 |
# File 'app/concerns/postburner/properties.rb', line 204 def queue_name @queue_name || self.class.queue || Postburner.configuration.default_queue end |
#retry_delay_for_attempt(attempt) ⇒ Integer
Calculates the retry delay for the given attempt.
Uses the class-level retry_delay configuration, which can be:
-
Integer: Fixed delay in seconds
-
Proc: Called with attempt number (0-based), returns delay in seconds
-
nil: Defaults to 5 seconds
310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'app/concerns/postburner/properties.rb', line 310 def retry_delay_for_attempt(attempt) delay_config = self.class.retry_delay || Postburner.configuration.default_retry_delay case delay_config when Proc delay_config.call(attempt).to_i when Integer delay_config else 2 ** attempt # Fallback to default exponential backoff end end |
#should_retry? ⇒ Boolean
Checks if this job should retry after a failure.
Returns true if max_retries is configured and the current attempt count is less than max_retries.
278 279 280 281 |
# File 'app/concerns/postburner/properties.rb', line 278 def should_retry? max = self.class.max_retries || Postburner.configuration.default_max_retries attempt_count.to_i < max.to_i end |
#ttr ⇒ Integer?
Returns the TTR (time-to-run) for this job instance.
Checks instance-level override first, then falls back to class-level configuration.
257 258 259 |
# File 'app/concerns/postburner/properties.rb', line 257 def ttr @ttr || self.class.ttr end |
#tube_name ⇒ String Also known as: expanded_tube_name
Returns the full Beanstalkd tube name with environment prefix.
Expands the queue name to include the environment prefix (e.g., ‘critical’ becomes ‘postburner.development.critical’).
218 219 220 |
# File 'app/concerns/postburner/properties.rb', line 218 def tube_name Postburner.configuration.(queue_name) end |