Module: ActiveJobLog::Loggeable::ClassMethods
- Defined in:
- lib/active_job_log/loggeable.rb
Instance Method Summary collapse
- #find_or_create_job(job_id) ⇒ Object
- #infer_duration_attr_from_status(status) ⇒ Object
- #status_to_params(status) ⇒ Object
- #update_job!(job_id, status, params = {}) ⇒ Object
Instance Method Details
#find_or_create_job(job_id) ⇒ Object
46 47 48 |
# File 'lib/active_job_log/loggeable.rb', line 46 def find_or_create_job(job_id) where(job_id: job_id).where.not(status: :failed).last || create(job_id: job_id) end |
#infer_duration_attr_from_status(status) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/active_job_log/loggeable.rb', line 58 def infer_duration_attr_from_status(status) case status when :queued :queued_at when :pending :started_at when :finished, :failed :ended_at else fail "invalid status" end end |
#status_to_params(status) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/active_job_log/loggeable.rb', line 50 def status_to_params(status) time_attr = infer_duration_attr_from_status(status) { time_attr => DateTime.current, status: status } end |
#update_job!(job_id, status, params = {}) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/active_job_log/loggeable.rb', line 39 def update_job!(job_id, status, params = {}) params.merge!(status_to_params(status)) job = find_or_create_job(job_id) job.update!(params) job end |