Class: BossQueue::Job
- Inherits:
-
AWS::Record::HashModel
- Object
- AWS::Record::HashModel
- BossQueue::Job
- Defined in:
- lib/boss_queue/job.rb
Instance Attribute Summary collapse
-
#queue_name ⇒ Object
Returns the value of attribute queue_name.
Instance Method Summary collapse
- #enqueue ⇒ Object
- #enqueue_with_delay(delay) ⇒ Object
- #fail(err) ⇒ Object
- #retry_delay ⇒ Object
-
#sqs_queue=(queue_obj) ⇒ Object
:nodoc:.
- #work ⇒ Object
Instance Attribute Details
#queue_name ⇒ Object
Returns the value of attribute queue_name.
6 7 8 |
# File 'lib/boss_queue/job.rb', line 6 def queue_name @queue_name end |
Instance Method Details
#enqueue ⇒ Object
24 25 26 |
# File 'lib/boss_queue/job.rb', line 24 def enqueue sqs_queue.(id.to_s) end |
#enqueue_with_delay(delay) ⇒ Object
28 29 30 |
# File 'lib/boss_queue/job.rb', line 28 def enqueue_with_delay(delay) sqs_queue.(id.to_s, :delay_seconds => [900, [0, delay].max].min) end |
#fail(err) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/boss_queue/job.rb', line 48 def fail(err) self.failed_attempts ||= 0 self.failed_attempts += 1 self.exception_name = err.class.to_s self. = err. self.stacktrace = err.backtrace[0, 7].join("\n") if failure_action == 'retry' && retry_delay enqueue_with_delay(retry_delay) else self.failed = true end self.save! end |
#retry_delay ⇒ Object
64 65 66 67 |
# File 'lib/boss_queue/job.rb', line 64 def retry_delay return nil if failed_attempts.nil? || failed_attempts > 4 60 * 2**(failed_attempts - 1) end |
#sqs_queue=(queue_obj) ⇒ Object
:nodoc:
69 70 71 |
# File 'lib/boss_queue/job.rb', line 69 def sqs_queue=(queue_obj) # :nodoc: @sqs_queue = queue_obj end |
#work ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/boss_queue/job.rb', line 32 def work begin klass = constantize(model_class_name) if model_id target = klass.find(model_id) else target = klass end args = JSON.parse(job_arguments) target.send(job_method, *args) destroy rescue StandardError => err fail(err) end end |