Skip to content

Commit 8164b08

Browse files
committed
Add reminder deadline job and backup RDS
1 parent 8fe4485 commit 8164b08

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

app/jobs/backup_db_rds.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
24+
end
25+
end

clock.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ 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
3835
end
36+
37+
every(1.day, "Send reminder emails", at: "12:00", if: lambda { |_| Rails.env.production?}) do
38+
ReminderDeadlineJob.perform_now
39+
end
40+
3941
end

lib/tasks/initiate_reminder_deadline_job.rake

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

0 commit comments

Comments
 (0)