houdini/lib/tasks/scheduler.rake

27 lines
874 B
Ruby
Raw Normal View History

# 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
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
task :heroku_scheduled_job, [:name] => :environment do |_t, args|
job_name = args[:name]
# Fetch all the super admin emails so we can send a report
enum = ScheduledJobs.send(job_name)
results = ''
enum.each do |lamb|
result = lamb.call
results += "Success: #{result}\n"
rescue Exception => e
results += "Failure: #{e}\n"
end
2019-11-07 20:51:34 +00:00
GenericMailer.admin_notice(
subject: "Scheduled job results on CommitChange for '#{job_name}'",
body: results.empty? ? 'No jobs to run today.' : results
2019-11-07 20:51:34 +00:00
).deliver_later
end