Created
April 9, 2025 22:48
-
-
Save darrenterhune/c1376ec3e97f19ad146883ddd5d8dbcb to your computer and use it in GitHub Desktop.
Rake tasks for Guardian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
namespace :nightly do | |
# | |
### Sms Managements cleanup | |
# | |
desc "Delete sms_managements that don't have an associated flight_report" | |
task delete_sms_managements: :environment do | |
SmsManagement.left_joins(:flight_report).where(flight_reports: { id: nil }).destroy_all | |
end | |
# | |
### Employee Weekly Requirements | |
# | |
desc 'Sets a users boolean weekly reports back to false to force them to re-do' | |
task set_users_weekly_booleans: :environment do | |
exit unless Time.zone.now.sunday? | |
User.update_all(logbook: false, safety_meeting: false, power_check: false, location_information: false) | |
end | |
# | |
### Calendar Tracking | |
# | |
desc 'Checks if calendar tracking items need to have certification renewed and emails important people' | |
task check_calendar_tracking_items: :environment do | |
calendars = | |
Calendar | |
.includes(calendar_categories: :calendar_items) | |
.where('calendar_items.next_certification_date' => 15.days.from_now.all_day) | |
if calendars.present? | |
calendars.each do |calendar| | |
AppMailer.with(calendar).send_calendar_items_needing_updated_certification.deliver_now | |
end | |
end | |
end | |
# | |
### Job Bookings | |
# | |
desc 'Sends emails regarding job_bookings 1.week.from_now' | |
task send_job_bookings_week_before: :environment do | |
job_bookings = JobBooking.where(date: 1.week.from_now.all_day) | |
if job_bookings.present? | |
jobs_bookings.each { |job_booking| AppMailer.with(job_booking).send_job_booking_week_before.deliver_now } | |
end | |
end | |
desc 'Sends emails regarding job_bookings 1.day.from_now' | |
task send_job_bookings_day_before: :environment do | |
job_bookings = JobBooking.where(date: 1.day.from_now.all_day) | |
if job_bookings.present? | |
jobs_bookings.each { |job_booking| AppMailer.with(job_booking).send_job_booking_day_before.deliver_now } | |
end | |
end | |
desc 'Sends emails regarding job_bookings today' | |
task send_job_bookings_today: :environment do | |
job_bookings = JobBooking.where(date: Time.zone.now.all_day) | |
if job_bookings.present? | |
jobs_bookings.each { |job_booking| AppMailer.with(job_booking).send_job_booking_today.deliver_now } | |
end | |
end | |
# | |
### Non Conformances | |
# | |
desc 'Sends emails regarding non_conformance CAP# Immediate Short term action required where created_at is 7.days.ago' | |
task send_non_conformance_seven_days_after: :environment do | |
non_conformances = NonConformance.where(created_at: 7.days.ago.all_day, closed: false).select('id, created_at') | |
AppMailer.with(non_conformances).send_non_conformance_seven_days.deliver_now if non_conformances.present? | |
end | |
desc 'Sends emails regarding non_conformance CAP# Root Cause and Corrective long term action plan is due where created_at is 27.days.ago' | |
task send_non_conformance_twenty_seven_days_after: :environment do | |
non_conformances = NonConformance.where(created_at: 27.days.ago.all_day, closed: false).select('id, created_at') | |
AppMailer.with(non_conformances).send_non_conformance_twenty_seven_days.deliver_now if non_conformances.present? | |
end | |
desc 'Sends emails regarding non_conformance CAP# Implementation and verification of long-term action is required where created_at is 37.days.ago' | |
task send_non_conformance_thirty_seven_days_after: :environment do | |
non_conformances = NonConformance.where(created_at: 37.days.ago.all_day, closed: false).select('id, created_at') | |
AppMailer.with(non_conformances).send_non_conformance_thirty_seven_days.deliver_now if non_conformances.present? | |
end | |
desc 'Sends emails regarding non_conformance CAP# 3 month conformity check is required where created_at is 97.days.ago' | |
task send_non_conformance_three_months_after: :environment do | |
non_conformances = NonConformance.where(created_at: 97.days.ago.all_day, closed: false).select('id, created_at') | |
AppMailer.with(non_conformances).send_non_conformance_three_months.deliver_now if non_conformances.present? | |
end | |
desc 'Sends emails regarding non_conformance CAP# 6 month conformity check is required where created_at is 190.days.ago' | |
task send_non_conformance_six_months_after: :environment do | |
non_conformances = NonConformance.where(created_at: 190.days.ago.all_day, closed: false).select('id, created_at') | |
AppMailer.with(non_conformances).send_non_conformance_six_months.deliver_now if non_conformances.present? | |
end | |
desc 'Sends emails regarding non_conformance CAP# 12 month conformity check is required where created_at is 372.days.ago' | |
task send_non_conformance_twelve_months_after: :environment do | |
non_conformances = NonConformance.where(created_at: 372.days.ago.all_day, closed: false).select('id, created_at') | |
AppMailer.with(non_conformances).send_non_conformance_twelve_months.deliver_now if non_conformances.present? | |
end | |
# | |
### Accident Reports | |
# | |
desc 'Sends emails when accident_reports target_date is due' | |
task send_accident_reports_when_target_date_today: :environment do | |
accident_reports = AccidentReport.where(target_date: Time.zone.now.all_day, closed: false).select('id') | |
if accident_reports.present? | |
AppMailer.with(accident_reports).send_accident_reports_when_target_date_today.deliver_now | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment