scheduled_touch_job.rb 429 B

12345678910111213141516
  1. class ScheduledTouchJob < ApplicationJob
  2. include HasActiveJobLock
  3. def lock_key
  4. # "ScheduledTouchJob/User/42"
  5. "#{self.class.name}/#{arguments[0]}/#{arguments[1]}"
  6. end
  7. def self.touch_at(object, date)
  8. set(wait_until: date).perform_later(object.class.to_s, object.id)
  9. end
  10. def perform(klass_name, id)
  11. klass_name.constantize.find_by(id: id)&.touch # rubocop:disable Rails/SkipsModelValidations
  12. end
  13. end