Skip to content

Commit

Permalink
Write a log feed after the backup failed or finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Jul 10, 2009
1 parent cb3768e commit 6eb0355
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ def initialize(config_file)

def finished
@logger.debug "The backup finished."
write_feed!
end

def failed(exception)
@logger.debug "#{exception.message} #{exception.backtrace.join("\n")}"
@logger.debug "[!] The backup has failed."
write_feed!
raise exception
end

def write_feed!
@logger.write_feed(@config['log_feed'])
end

def run!
begin
create_mysql_dump!
Expand Down
11 changes: 10 additions & 1 deletion test/backup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,35 @@
end

it "should catch any type of exception that was raised during the run and terminate the EC2 instance if one was launched and call #failed" do
@backup.stubs(:finished)

@backup.ec2_instance_id = 'i-nonexistant'
@backup.stubs(:create_mysql_dump!).raises 'oh noes!'
@backup.expects(:failed).with { |exception| exception.message == 'oh noes!' }
@backup.expects(:take_backup_volume_offline!)
@backup.run!
end

it "should log an exception, log that a failure occured, and re-raise the exception" do
it "should report that the backup failed and re-raise the exception" do
exception = nil
begin; raise 'oh noes!'; rescue Exception => e; exception = e; end

@backup.expects(:write_feed!)
lambda { @backup.failed(exception) }.should.raise exception.class
@backup.logger.logged.first.should.include 'oh noes!'
@backup.logger.logged.last.should == "[!] The backup has failed."
end

it "should report that the backup has finished" do
@backup.expects(:write_feed!)
@backup.finished
@backup.logger.logged.last.should == "The backup finished."
end

it "should write the feed of the current log" do
@backup.logger.expects(:write_feed).with(@config['log_feed'])
@backup.write_feed!
end
end

describe "Fingertips::Backup, concerning the MySQL backup" do
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
java_home: /Library/Java/Home
log_feed: /var/www/backup_feed/backup_feed.xml
ec2:
zone: eu-west-1a
ebs: vol-nonexistant
Expand Down

0 comments on commit 6eb0355

Please sign in to comment.