Class: Lambdakiq::Job
- Inherits:
-
Object
- Object
- Lambdakiq::Job
- Defined in:
- lib/lambdakiq/job.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Class Method Summary collapse
Instance Method Summary collapse
- #active_job ⇒ Object
- #execute ⇒ Object
- #executions ⇒ Object
-
#initialize(record) ⇒ Job
constructor
A new instance of Job.
- #job_data ⇒ Object
- #perform ⇒ Object
- #provider_job_id ⇒ Object
- #queue ⇒ Object
Constructor Details
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
4 5 6 |
# File 'lib/lambdakiq/job.rb', line 4 def error @error end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
4 5 6 |
# File 'lib/lambdakiq/job.rb', line 4 def record @record end |
Class Method Details
.handler(event) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/lambdakiq/job.rb', line 8 def handler(event) records = Event.records(event) jobs = records.map { |record| new(record) } jobs.each(&:perform) failed_jobs = jobs.select { |j| j.error } item_failures = failed_jobs.map { |j| { itemIdentifier: j.provider_job_id } } { batchItemFailures: item_failures } end |
Instance Method Details
#active_job ⇒ Object
31 32 33 |
# File 'lib/lambdakiq/job.rb', line 31 def active_job @active_job ||= ActiveJob::Base.deserialize(job_data) end |
#execute ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/lambdakiq/job.rb', line 55 def execute ActiveJob::Base.execute(job_data) rescue Exception => e increment_executions perform_error(e) end |
#executions ⇒ Object
39 40 41 |
# File 'lib/lambdakiq/job.rb', line 39 def executions active_job.executions end |
#job_data ⇒ Object
24 25 26 27 28 29 |
# File 'lib/lambdakiq/job.rb', line 24 def job_data @job_data ||= JSON.parse(record.body).tap do |data| data['provider_job_id'] = record. data['executions'] = record.receive_count - 1 end end |
#perform ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/lambdakiq/job.rb', line 47 def perform if fifo_delay? fifo_delay return end execute end |
#provider_job_id ⇒ Object
43 44 45 |
# File 'lib/lambdakiq/job.rb', line 43 def provider_job_id active_job.provider_job_id end |