class Employer::Mongoid::Pipeline

Public Instance Methods

clear() click to toggle source
# File lib/employer-mongoid/pipeline.rb, line 19
def clear
  Employer::Mongoid::Job.destroy_all
end
complete(job) click to toggle source
# File lib/employer-mongoid/pipeline.rb, line 23
def complete(job)
  Employer::Mongoid::Job.find(job.id).destroy
end
dequeue() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/employer-mongoid/pipeline.rb, line 31
def fail(job)
  Employer::Mongoid::Job.find(job.id).update_attributes(state: :failed)
end
reset(job) click to toggle source
# File lib/employer-mongoid/pipeline.rb, line 27
def reset(job)
  Employer::Mongoid::Job.find(job.id).update_attributes(state: :free)
end