Created
January 10, 2014 14:30
-
-
Save jadon1979/8354438 to your computer and use it in GitHub Desktop.
Job Models / Concern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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