2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'qx'
|
|
|
|
require 'delayed_job'
|
|
|
|
|
|
|
|
module DelayedJobHelper
|
2019-07-30 21:29:24 +00:00
|
|
|
# Create a serialized delayed job handler for use in inserting new delayed jobs with raw sql
|
|
|
|
# Be sure to wrap the handler in double quotes when inserting, not single
|
|
|
|
def self.create_handler(obj, method_name, args)
|
|
|
|
Delayed::PerformableMethod.new(obj, method_name, args).to_yaml.to_s
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# Manually enqueue a job
|
2019-07-30 21:29:24 +00:00
|
|
|
def self.enqueue_job(obj, method_name, args, options = {})
|
2018-03-25 17:30:42 +00:00
|
|
|
handler = Delayed::PerformableMethod.new(obj, method_name, args).to_yaml.to_s
|
|
|
|
Qx.insert_into(:delayed_jobs)
|
2019-07-30 21:29:24 +00:00
|
|
|
.values(
|
2018-03-25 17:30:42 +00:00
|
|
|
created_at: Time.current,
|
|
|
|
updated_at: Time.current,
|
|
|
|
priority: options[:priority] || 0,
|
|
|
|
attempts: 0,
|
|
|
|
handler: handler,
|
|
|
|
run_at: options[:run_at] || Time.current,
|
|
|
|
queue: options[:queue]
|
2019-07-30 21:29:24 +00:00
|
|
|
).returning('*').execute
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|