Class: Eyeloupe::Processors::Job
- Inherits:
-
Object
- Object
- Eyeloupe::Processors::Job
- Includes:
- Singleton
- Defined in:
- lib/eyeloupe/processors/job.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #args_info(job) ⇒ Array?
- #complete(event) ⇒ Object
- #discard(event) ⇒ Object
- #failed(event) ⇒ Object
-
#initialize ⇒ Job
constructor
A new instance of Job.
- #process(event) ⇒ Object
- #run(event) ⇒ Object
Constructor Details
#initialize ⇒ Job
Returns a new instance of Job.
10 11 12 |
# File 'lib/eyeloupe/processors/job.rb', line 10 def initialize @subs = [] end |
Instance Attribute Details
#subs ⇒ Array
8 9 10 |
# File 'lib/eyeloupe/processors/job.rb', line 8 def subs @subs end |
Instance Method Details
#args_info(job) ⇒ Array?
69 70 71 72 73 |
# File 'lib/eyeloupe/processors/job.rb', line 69 def args_info(job) if job.class.log_arguments? && job.arguments.any? job.arguments end end |
#complete(event) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/eyeloupe/processors/job.rb', line 37 def complete(event) job = event.payload[:job] existing = Eyeloupe::Job.where(job_id: job.job_id).first if existing&.failed? Eyeloupe::Job.where(job_id: job.job_id).update(completed_at: Time.now.utc, retry: existing.retry + 1) else Eyeloupe::Job.where(job_id: job.job_id).update( status: :completed, completed_at: Time.now.utc, retry: (job.executions.zero? ? 1 : job.executions) - 1 ) end end |
#discard(event) ⇒ Object
61 62 63 64 65 |
# File 'lib/eyeloupe/processors/job.rb', line 61 def discard(event) job = event.payload[:job] Eyeloupe::Job.where(job_id: job.job_id).update(status: :discarded) end |
#failed(event) ⇒ Object
54 55 56 57 58 |
# File 'lib/eyeloupe/processors/job.rb', line 54 def failed(event) job = event.payload[:job] Eyeloupe::Job.where(job_id: job.job_id).update(status: :failed) end |
#process(event) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/eyeloupe/processors/job.rb', line 15 def process(event) job = event.payload[:job] Eyeloupe::Job.create( classname: job.class.name, job_id: job.job_id, queue_name: queue_name(event), adapter: adapter_name(event), scheduled_at: scheduled_at(event), status: :enqueued, args: (args_info(job) || {}).to_json ) end |