Class: Employer::Mongoid::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/employer-mongoid/pipeline.rb

Instance Method Summary collapse

Instance Method Details

#complete(job) ⇒ Object



19
20
21
# File 'lib/employer-mongoid/pipeline.rb', line 19

def complete(job)
  Employer::Mongoid::Job.find(job.id).destroy
end

#dequeueObject



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

#fail(job) ⇒ Object



27
28
29
# File 'lib/employer-mongoid/pipeline.rb', line 27

def fail(job)
  Employer::Mongoid::Job.find(job.id).update_attributes(state: :failed)
end

#reset(job) ⇒ Object



23
24
25
# File 'lib/employer-mongoid/pipeline.rb', line 23

def reset(job)
  Employer::Mongoid::Job.find(job.id).update_attributes(state: :free)
end