This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Rakefile
68 lines (51 loc) · 1.67 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require "newrelic_rpm"
require "pg"
require "pgbackups-archive"
require "securerandom"
# spec = Gem::Specification.find_by_name "pgbackups-archive"
# load "#{spec.gem_dir}/lib/tasks/pgbackups_archive.rake"
namespace :db do
desc "Generate a table with dummy records"
task :generate do
if ENV["DATABASE_URL"]
db = URI.parse(ENV["DATABASE_URL"])
dbname = db.path[1..-1]
host = db.host
user = db.user
password = db.password
else
dbname = "pgbackups_archive_dummy"
host = "localhost"
user = ENV["USER"]
password = ""
end
conn = PG.connect(dbname: dbname, host: host, user: user, password: password)
puts "Creating `records` table..."
conn.exec("DROP TABLE records")
conn.exec("CREATE TABLE IF NOT EXISTS records (content text)")
# Create 1000 1MB records to produce a 1GB database
content = SecureRandom.base64(750000)
total = 1000
total.times do |index|
print "\rPopulating record #{index+1}/1000"
conn.exec("INSERT INTO records (content) VALUES ('#{content}')")
end
count = conn.exec("SELECT COUNT(*) FROM records")
puts "\nCreated #{count.first["count"]} records"
end
end
class RunPgbackupsArchive
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
def call
Heroku::Client::PgbackupsArchive.perform
end
add_transaction_tracer :call, category: :task
end
namespace :pgbackups do
desc "Perform a pgbackups backup then archive to S3."
task :archive do
RunPgbackupsArchive.new.call
end
end
NewRelic::Agent.manual_start app_name: "pgbackups-archive-dummy",
transaction_tracer: { transaction_threshold: 1.5 }