Skip to content

Instantly share code, notes, and snippets.

@jadon1979
Created January 10, 2014 14:30
Show Gist options
  • Select an option

  • Save jadon1979/8354438 to your computer and use it in GitHub Desktop.

Select an option

Save jadon1979/8354438 to your computer and use it in GitHub Desktop.
Job Models / Concern
require 'active_support/concern'
module Concerns
module JobStates
extend ActiveSupport::Concern
def self.extended(base)
base.class_eval do
def self.job_is_pending(id)
update_job id, 1, "Pending"
end
def self.job_is_processing(id, status, result = "")
update_job id, 2, status, result
end
def self.job_is_complete(id, status, result = "")
update_job id, 3, status, result
end
def self.job_is_errored(id, result = "")
update_job id, 4, "Failed", result
end
def self.update_job(id, code, status, result = "")
job_queue = self.find_by_id(id)
job_queue.tap do |job|
job.status_code = code
job.status = status
job.result = result unless result == ""
job.save!
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment