lib/dumper/job.rb in dumper-0.3.0 vs lib/dumper/job.rb in dumper-0.4.0
- old
+ new
@@ -1,5 +1,6 @@
+require 'ostruct'
require 'posix/spawn'
module Dumper
class Job
include POSIX::Spawn
@@ -23,18 +24,15 @@
exit!(true) # Do not use exit or abort to skip at_exit execution, or pid could get deleted on thin
end
def perform(server)
# Initialize database
- case server[:type]
- when 'mysql'
- @database = Dumper::Database::MySQL.new(@stack)
- when 'mongodb'
- @database = Dumper::Database::MongoDB.new(@stack)
- when 'redis'
- @database = Dumper::Database::Redis.new(@stack)
+ server_type = server[:type].to_sym
+ if Dumper::Stack::DATABASES.keys.include?(server_type)
+ @database = Dumper::Stack::DATABASES[server_type].new(@stack)
+ @database.config = OpenStruct.new(@stack.configs[Dumper::Stack::DATABASES.key(@database.class)])
else
- abort_with "invalid server type: #{server[:type]}"
+ abort_with "invalid server type: #{server_type}"
end
# Prepare
json = @agent.api_request('backup/prepare', :params => { :server_id => server[:id], :manual => server[:manual].to_s, :ext => @database.file_ext })
abort_with('backup/prepare failed') unless json[:status] == 'ok'