2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'scheduled_jobs'
|
|
|
|
|
|
|
|
desc "For use with Heroku's Scheduler add-on"
|
|
|
|
|
|
|
|
# We use a single rake call so we can catch and send any errors that happen in the job
|
2019-07-30 21:29:24 +00:00
|
|
|
task :heroku_scheduled_job, [:name] => :environment do |_t, args|
|
2018-03-25 17:30:42 +00:00
|
|
|
job_name = args[:name]
|
|
|
|
# Fetch all the super admin emails so we can send a report
|
|
|
|
enum = ScheduledJobs.send(job_name)
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
results = ''
|
2018-03-25 17:30:42 +00:00
|
|
|
enum.each do |lamb|
|
2019-07-30 21:29:24 +00:00
|
|
|
result = lamb.call
|
|
|
|
results += "Success: #{result}\n"
|
|
|
|
rescue Exception => e
|
|
|
|
results += "Failure: #{e}\n"
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
2021-04-19 23:25:46 +00:00
|
|
|
|
2019-11-07 20:51:34 +00:00
|
|
|
GenericMailer.admin_notice(
|
2021-04-19 23:25:46 +00:00
|
|
|
subject: "Scheduled job results on #{Houdini.hoster.casual_name} for '#{job_name}'",
|
2019-07-30 21:29:24 +00:00
|
|
|
body: results.empty? ? 'No jobs to run today.' : results
|
2019-11-07 20:51:34 +00:00
|
|
|
).deliver_later
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|