summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/backup_job.rb21
-rw-r--r--db/migrate/20130205151844_add_queue_to_delayed_jobs.rb9
2 files changed, 25 insertions, 5 deletions
diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb
index b0a588f..a90726c 100644
--- a/app/models/backup_job.rb
+++ b/app/models/backup_job.rb
@@ -1,14 +1,25 @@
class BackupJob < ActiveRecord::Base
attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup
- after_create :start_the_backup
+ after_create :initiate_backup
private
- def start_the_backup
- if self.finished_at.nil?
+ def initiate_backup
+ self.delay.make_a_backup
+ end
+
+ def make_a_backup
+ if self.finished_at.nil?
+ original_directories = Dir.glob('/var/backups/GS5/*')
system "backup perform --trigger GS5 --config_file #{Rails.root.join('config','backup.rb')}"
- self.finished_at = Time.now
- self.status = 'done'
+ self.directory = (Dir.glob('/var/backups/GS5/*') - original_directories).first
+ if self.directory.blank?
+ self.state = 'unsuccessful'
+ else
+ self.size_of_the_backup = (`du -hs #{new_directory}`).split(/\t/).first
+ self.finished_at = Time.now
+ self.state = 'successful'
+ end
self.save
end
end
diff --git a/db/migrate/20130205151844_add_queue_to_delayed_jobs.rb b/db/migrate/20130205151844_add_queue_to_delayed_jobs.rb
new file mode 100644
index 0000000..072c8d4
--- /dev/null
+++ b/db/migrate/20130205151844_add_queue_to_delayed_jobs.rb
@@ -0,0 +1,9 @@
+class AddQueueToDelayedJobs < ActiveRecord::Migration
+ def self.up
+ add_column :delayed_jobs, :queue, :string
+ end
+
+ def self.down
+ remove_column :delayed_jobs, :queue
+ end
+end