Class: Employer::ActiveRecord::Pipeline
- Inherits:
-
Object
- Object
- Employer::ActiveRecord::Pipeline
- Defined in:
- lib/employer-activerecord/pipeline.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #complete(job) ⇒ Object
- #dequeue ⇒ Object
- #enqueue(job_hash) ⇒ Object
- #fail(job) ⇒ Object
- #reset(job) ⇒ Object
Instance Method Details
#clear ⇒ Object
24 25 26 |
# File 'lib/employer-activerecord/pipeline.rb', line 24 def clear Employer::ActiveRecord::Job.destroy_all end |
#complete(job) ⇒ Object
28 29 30 |
# File 'lib/employer-activerecord/pipeline.rb', line 28 def complete(job) Employer::ActiveRecord::Job.find(job.id, lock: true).destroy end |
#dequeue ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/employer-activerecord/pipeline.rb', line 16 def dequeue if job = Employer::ActiveRecord::Job.free.order("created_at ASC").lock(true).first job.state = :locked job.save! {id: job.id, class: job.type, attributes: JSON.parse(job.properties)} end end |
#enqueue(job_hash) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/employer-activerecord/pipeline.rb', line 6 def enqueue(job_hash) job_attributes = { type: job_hash[:class], properties: job_hash[:attributes].to_json, state: :free } Employer::ActiveRecord::Job.create!(job_attributes).id end |
#fail(job) ⇒ Object
32 33 34 |
# File 'lib/employer-activerecord/pipeline.rb', line 32 def fail(job) Employer::ActiveRecord::Job.find(job.id, lock: true).update_attributes(state: :failed) end |
#reset(job) ⇒ Object
36 37 38 |
# File 'lib/employer-activerecord/pipeline.rb', line 36 def reset(job) Employer::ActiveRecord::Job.find(job.id, lock: true).update_attributes(state: :free) end |