From 8c975b85d1a8d42490dc43cc0c05caa155efaedd Mon Sep 17 00:00:00 2001 From: Tom Dooner Date: Mon, 7 Oct 2024 15:24:14 -0700 Subject: [PATCH] 1391: Automate data retention and weekly report jobs The `template-infra` v0.12.2 release contains built-in cron job support - just in time, too. Let's give it a shot with our data retention and weekly report jobs. --- app/lib/tasks/weekly_reports.rake | 11 +++++++++++ infra/app/app-config/env-config/scheduled_jobs.tf | 15 +++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 app/lib/tasks/weekly_reports.rake diff --git a/app/lib/tasks/weekly_reports.rake b/app/lib/tasks/weekly_reports.rake new file mode 100644 index 00000000..cb8e92e7 --- /dev/null +++ b/app/lib/tasks/weekly_reports.rake @@ -0,0 +1,11 @@ +namespace :weekly_reports do + desc "Send weekly reports (NYC and later others?)" + task send_all: :environment do + report_date = Time.now.in_time_zone("America/New_York").beginning_of_week + + WeeklyReportMailer + .with(site_id: "nyc", report_date: report_date.to_date) + .report_email + .deliver_now + end +end diff --git a/infra/app/app-config/env-config/scheduled_jobs.tf b/infra/app/app-config/env-config/scheduled_jobs.tf index 2c71b23d..9b925545 100644 --- a/infra/app/app-config/env-config/scheduled_jobs.tf +++ b/infra/app/app-config/env-config/scheduled_jobs.tf @@ -1,14 +1,17 @@ locals { - # The `cron` here is the literal name of the scheduled job. It can be anything you want. - # For example "file_upload_jobs" or "daily_report". Whatever makes sense for your use case. # The `task_command` is what you want your scheduled job to run, for example: ["poetry", "run", "flask"]. # Schedule expression defines the frequency at which the job should run. # The syntax for `schedule_expression` is explained in the following documentation: # https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-scheduled-rule-pattern.html scheduled_jobs = { - # cron = { - # task_command = ["python", "-m", "flask", "--app", "app.py", "cron"] - # schedule_expression = "cron(0 * ? * * *)" - # } + send_weekly_reports = { + task_command = ["bin/rails", "weekly_reports:send_all"] + schedule_expression = "cron(0 12 ? * MON *)" # Every Monday at 12pm UTC (7am EST / 8am EDT) + } + + redact_data = { + task_command = ["bin/rails", "data_deletion:redact_all"] + schedule_expression = "cron(0 14 ? * * *)" # Every day at 2pm UTC (9am EST / 10am EDT) + } } }