Skip to content

Commit

Permalink
Merge pull request #4798 from rubyforgood/reminder-deadline
Browse files Browse the repository at this point in the history
Add reminder deadline job and backup RDS
  • Loading branch information
awwaiid authored Nov 24, 2024
2 parents 8fe4485 + 5be43e4 commit 9ae32c4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
24 changes: 24 additions & 0 deletions app/jobs/backup_db_rds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# to be called from Clock
module BackupDbRds
def run
logger = Logger.new($stdout)
logger.info("Performing dump of the database.")

current_time = Time.current.strftime("%Y%m%d%H%M%S")

logger.info("Copying the database...")
backup_filename = "#{current_time}.rds.dump"
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}")

account_name = ENV["AZURE_STORAGE_ACCOUNT_NAME"]
account_key = ENV["AZURE_STORAGE_ACCESS_KEY"]

blob_client = Azure::Storage::Blob::BlobService.create(
storage_account_name: account_name,
storage_access_key: account_key
)

logger.info("Uploading #{backup_filename}")
blob_client.create_block_blob("backups", backup_filename, File.read(backup_filename))
end
end
1 change: 1 addition & 0 deletions app/jobs/reminder_deadline_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ReminderDeadlineJob < ApplicationJob

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

remind_these_partners.each do |partner|
ReminderDeadlineMailer.notify_deadline(partner).deliver_later
Expand Down
9 changes: 5 additions & 4 deletions clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ module Clockwork
end

every(4.hours, "Backup prod DB to Azure blob storage", if: lambda { |_| Rails.env.production? }) do
rake = Rake.application
rake.init
rake.load_rakefile
rake["backup_db_rds"].invoke
BackupDbRds.run
end

every(1.day, "Send reminder emails", at: "12:00", if: lambda { |_| Rails.env.production? }) do
ReminderDeadlineJob.perform_now
end
end
32 changes: 29 additions & 3 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
{
"ignored_warnings": [
{
"warning_type": "Command Injection",
"warning_code": 14,
"fingerprint": "0f98f6aeae590aca0d8eebf04dbd2dcaf4d1252822f138b4bcfe6e03455e5b4a",
"check_name": "Execute",
"message": "Possible command injection",
"file": "app/jobs/backup_db_rds.rb",
"line": 11,
"link": "https://brakemanscanner.org/docs/warning_types/command_injection/",
"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\"}\")",
"render_path": null,
"location": {
"type": "method",
"class": "BackupDbRds",
"method": "run"
},
"user_input": "ENV[\"DIAPER_DB_PASSWORD\"]",
"confidence": "Medium",
"cwe_id": [
77
],
"note": ""
},
{
"warning_type": "Dynamic Render Path",
"warning_code": 15,
"fingerprint": "82ef033042422190ef49507207d51ed6ccd9593483630925baf0bf6c5e65033e",
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/controllers/static_controller.rb",
"line": 25,
"line": 20,
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(template => \"static/#{params[:name]}\", {})",
"render_path": null,
Expand All @@ -18,6 +41,9 @@
},
"user_input": "params[:name]",
"confidence": "Medium",
"cwe_id": [
22
],
"note": ""
},
{
Expand All @@ -41,6 +67,6 @@
"note": ""
}
],
"updated": "2021-04-24 20:03:05 -0700",
"brakeman_version": "4.10.1"
"updated": "2024-11-24 09:44:01 -0500",
"brakeman_version": "6.2.1"
}
7 changes: 0 additions & 7 deletions lib/tasks/initiate_reminder_deadline_job.rake

This file was deleted.

0 comments on commit 9ae32c4

Please sign in to comment.