Skip to content

Commit 9ae32c4

Browse files
authored
Merge pull request #4798 from rubyforgood/reminder-deadline
Add reminder deadline job and backup RDS
2 parents 8fe4485 + 5be43e4 commit 9ae32c4

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

app/jobs/backup_db_rds.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# to be called from Clock
2+
module BackupDbRds
3+
def run
4+
logger = Logger.new($stdout)
5+
logger.info("Performing dump of the database.")
6+
7+
current_time = Time.current.strftime("%Y%m%d%H%M%S")
8+
9+
logger.info("Copying the database...")
10+
backup_filename = "#{current_time}.rds.dump"
11+
system("PGPASSWORD='#{ENV["DIAPER_DB_PASSWORD"]}' pg_dump -Fc -v --host=#{ENV["DIAPER_DB_HOST"]} --username=#{ENV["DIAPER_DB_USERNAME"]} --dbname=#{ENV["DIAPER_DB_DATABASE"]} -f #{backup_filename}")
12+
13+
account_name = ENV["AZURE_STORAGE_ACCOUNT_NAME"]
14+
account_key = ENV["AZURE_STORAGE_ACCESS_KEY"]
15+
16+
blob_client = Azure::Storage::Blob::BlobService.create(
17+
storage_account_name: account_name,
18+
storage_access_key: account_key
19+
)
20+
21+
logger.info("Uploading #{backup_filename}")
22+
blob_client.create_block_blob("backups", backup_filename, File.read(backup_filename))
23+
end
24+
end

app/jobs/reminder_deadline_job.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ReminderDeadlineJob < ApplicationJob
77

88
def perform
99
remind_these_partners = Partners::FetchPartnersToRemindNowService.new.fetch
10+
Rails.logger.info("Partners to remind: #{remind_these_partners.map(&:id)}")
1011

1112
remind_these_partners.each do |partner|
1213
ReminderDeadlineMailer.notify_deadline(partner).deliver_later

clock.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ module Clockwork
3131
end
3232

3333
every(4.hours, "Backup prod DB to Azure blob storage", if: lambda { |_| Rails.env.production? }) do
34-
rake = Rake.application
35-
rake.init
36-
rake.load_rakefile
37-
rake["backup_db_rds"].invoke
34+
BackupDbRds.run
35+
end
36+
37+
every(1.day, "Send reminder emails", at: "12:00", if: lambda { |_| Rails.env.production? }) do
38+
ReminderDeadlineJob.perform_now
3839
end
3940
end

config/brakeman.ignore

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
11
{
22
"ignored_warnings": [
3+
{
4+
"warning_type": "Command Injection",
5+
"warning_code": 14,
6+
"fingerprint": "0f98f6aeae590aca0d8eebf04dbd2dcaf4d1252822f138b4bcfe6e03455e5b4a",
7+
"check_name": "Execute",
8+
"message": "Possible command injection",
9+
"file": "app/jobs/backup_db_rds.rb",
10+
"line": 11,
11+
"link": "https://brakemanscanner.org/docs/warning_types/command_injection/",
12+
"code": "system(\"PGPASSWORD='#{ENV[\"DIAPER_DB_PASSWORD\"]}' pg_dump -Fc -v --host=#{ENV[\"DIAPER_DB_HOST\"]} --username=#{ENV[\"DIAPER_DB_USERNAME\"]} --dbname=#{ENV[\"DIAPER_DB_DATABASE\"]} -f #{\"#{Time.current.strftime(\"%Y%m%d%H%M%S\")}.rds.dump\"}\")",
13+
"render_path": null,
14+
"location": {
15+
"type": "method",
16+
"class": "BackupDbRds",
17+
"method": "run"
18+
},
19+
"user_input": "ENV[\"DIAPER_DB_PASSWORD\"]",
20+
"confidence": "Medium",
21+
"cwe_id": [
22+
77
23+
],
24+
"note": ""
25+
},
326
{
427
"warning_type": "Dynamic Render Path",
528
"warning_code": 15,
629
"fingerprint": "82ef033042422190ef49507207d51ed6ccd9593483630925baf0bf6c5e65033e",
730
"check_name": "Render",
831
"message": "Render path contains parameter value",
932
"file": "app/controllers/static_controller.rb",
10-
"line": 25,
33+
"line": 20,
1134
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
1235
"code": "render(template => \"static/#{params[:name]}\", {})",
1336
"render_path": null,
@@ -18,6 +41,9 @@
1841
},
1942
"user_input": "params[:name]",
2043
"confidence": "Medium",
44+
"cwe_id": [
45+
22
46+
],
2147
"note": ""
2248
},
2349
{
@@ -41,6 +67,6 @@
4167
"note": ""
4268
}
4369
],
44-
"updated": "2021-04-24 20:03:05 -0700",
45-
"brakeman_version": "4.10.1"
70+
"updated": "2024-11-24 09:44:01 -0500",
71+
"brakeman_version": "6.2.1"
4672
}

lib/tasks/initiate_reminder_deadline_job.rake

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)