otwarchive-symphonyarchive/app/models/concerns/async_with_active_job.rb
2026-03-11 22:22:11 +00:00

17 lines
529 B
Ruby

# A concern defining the async/async_after_commit functions, which allow
# instance methods on an object to be used as ActiveJobs.
module AsyncWithActiveJob
extend ActiveSupport::Concern
included do
class_attribute :async_job_class, default: InstanceMethodJob
end
def async(*args, job_class: async_job_class, **kwargs)
job_class.perform_later(self, *args, **kwargs)
end
def async_after_commit(*args, job_class: async_job_class, **kwargs)
job_class.perform_after_commit(self, *args, **kwargs)
end
end