2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:20:18 +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 '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
|
2019-11-07 20:51:34 +00:00
|
|
|
GenericMailer.admin_notice(
|
2018-03-25 17:30:42 +00:00
|
|
|
subject: "Scheduled job results on CommitChange 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
|