Class: PgbackupsArchive::Job
- Inherits:
-
Object
- Object
- PgbackupsArchive::Job
- Defined in:
- lib/pgbackups-archive/job.rb
Instance Attribute Summary collapse
-
#backup_url ⇒ Object
Returns the value of attribute backup_url.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
Class Method Summary collapse
Instance Method Summary collapse
- #archive ⇒ Object
- #call ⇒ Object
- #capture ⇒ Object
- #delete ⇒ Object
- #download ⇒ Object
- #expire ⇒ Object
-
#initialize(attrs = {}) ⇒ Job
constructor
A new instance of Job.
Constructor Details
#initialize(attrs = {}) ⇒ Job
Returns a new instance of Job.
15 16 17 18 |
# File 'lib/pgbackups-archive/job.rb', line 15 def initialize(attrs={}) Heroku::Command.load @client = Heroku::Command::Pg.new([], :app => ENV["PGBACKUPS_APP"]) end |
Instance Attribute Details
#backup_url ⇒ Object
Returns the value of attribute backup_url.
9 10 11 |
# File 'lib/pgbackups-archive/job.rb', line 9 def backup_url @backup_url end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/pgbackups-archive/job.rb', line 8 def client @client end |
#created_at ⇒ Object
Returns the value of attribute created_at.
9 10 11 |
# File 'lib/pgbackups-archive/job.rb', line 9 def created_at @created_at end |
Class Method Details
.call ⇒ Object
11 12 13 |
# File 'lib/pgbackups-archive/job.rb', line 11 def self.call new.call end |
Instance Method Details
#archive ⇒ Object
28 29 30 31 32 |
# File 'lib/pgbackups-archive/job.rb', line 28 def archive if PgbackupsArchive::Storage.new(key, file).store client.display "Backup archived" end end |
#call ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/pgbackups-archive/job.rb', line 20 def call # expire # Disabled b/c Heroku seems to be keeping only 2 on its own capture download archive delete end |
#capture ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pgbackups-archive/job.rb', line 34 def capture = client.send(:generate_resolver).resolve(database) backup = client.send(:hpg_client, ).backups_capture client.send(:poll_transfer, "backup", backup[:uuid]) self.created_at = backup[:created_at] self.backup_url = Heroku::Client::HerokuPostgresqlApp .new(ENV["PGBACKUPS_APP"]).transfers_public_url(backup[:num])[:url] end |
#delete ⇒ Object
45 46 47 |
# File 'lib/pgbackups-archive/job.rb', line 45 def delete File.delete(temp_file) end |
#download ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pgbackups-archive/job.rb', line 49 def download File.open(temp_file, "wb") do |output| streamer = lambda do |chunk, remaining_bytes, total_bytes| output.write chunk end # https://github.com/excon/excon/issues/475 Excon.get backup_url, :response_block => streamer, :omit_default_port => true end end |
#expire ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pgbackups-archive/job.rb', line 62 def expire transfers = client.send(:hpg_app_client, ENV["PGBACKUPS_APP"]).transfers .select { |b| b[:from_type] == "pg_dump" && b[:to_type] == "gof3r" } .sort_by { |b| b[:created_at] } if transfers.size > pgbackups_to_keep backup_id = "b%03d" % transfers.first[:num] backup_num = client.send(:backup_num, backup_id) expire_backup(backup_num) client.display "Backup #{backup_id} expired" end end |