active_job_lock.rb 516 B

123456789101112131415161718192021
  1. class ActiveJobLock < ApplicationModel
  2. def of?(active_job)
  3. active_job.job_id == active_job_id
  4. end
  5. def peform_pending?
  6. updated_at == created_at
  7. end
  8. def transfer_to(active_job)
  9. logger.info "Transferring ActiveJobLock with id '#{id}' from active_job_id '#{active_job_id}' to active_job_id '#{active_job_id}'."
  10. reset_time_stamp = Time.zone.now
  11. update!(
  12. active_job_id: active_job.job_id,
  13. created_at: reset_time_stamp,
  14. updated_at: reset_time_stamp
  15. )
  16. end
  17. end