Class: Employer::Mongoid::Pipeline
- Inherits:
-
Object
- Object
- Employer::Mongoid::Pipeline
- Defined in:
- lib/employer-mongoid/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
19 20 21 |
# File 'lib/employer-mongoid/pipeline.rb', line 19 def clear Employer::Mongoid::Job.destroy_all end |
#complete(job) ⇒ Object
23 24 25 |
# File 'lib/employer-mongoid/pipeline.rb', line 23 def complete(job) Employer::Mongoid::Job.find(job.id).destroy end |
#dequeue ⇒ Object
13 14 15 16 17 |
# File 'lib/employer-mongoid/pipeline.rb', line 13 def dequeue if job = Employer::Mongoid::Job.free.asc(:created_at).find_and_modify({"$set" => {state: :locked}}, new: true) {id: job.id, class: job.type, attributes: job.properties} end end |
#enqueue(job_hash) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/employer-mongoid/pipeline.rb', line 4 def enqueue(job_hash) job_attributes = { type: job_hash[:class], properties: job_hash[:attributes] } Employer::Mongoid::Job.create!(job_attributes).id end |