dumper 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,10 +45,12 @@ module Dumper
45
45
  log "sleeping #{sec} seconds for agent/register.", :debug
46
46
  sleep sec
47
47
  json = send_request(api: 'agent/register', json: MultiJson.encode(register_hash))
48
- end until json[:status] == 'ok'
48
+ end until json[:status]
49
+
50
+ return log("agent stopped: #{json.to_s}") if json[:status] == 'error'
49
51
 
50
- log 'agent started.'
51
52
  @token = json[:token]
53
+ log "agent started as #{@token ? 'primary' : 'secondary'}"
52
54
  sleep 1.hour unless @token
53
55
 
54
56
  loop do
@@ -2,7 +2,7 @@ module Dumper
2
2
  module Database
3
3
  class MySQL < Base
4
4
  def command
5
- "mysqldump #{connection_options} #{additional_options} #{@stack.activerecord_config['database']} | gzip"
5
+ "#{@stack.dump_tool(:mysqldump)} #{connection_options} #{additional_options} #{@stack.activerecord_config['database']} | gzip"
6
6
  end
7
7
 
8
8
  protected
@@ -1,5 +1,7 @@
1
1
  module Dumper
2
2
  class Stack
3
+ DUMP_TOOLS = {}
4
+
3
5
  attr_accessor :rails_env, :dispatcher, :framework, :rackup, :activerecord_config
4
6
 
5
7
  def initialize
@@ -30,12 +32,28 @@ module Dumper
30
32
  rails_version: @rails_version,
31
33
  dispatcher: @dispatcher,
32
34
  activerecord_config: @activerecord_config.reject{|k,v| k == 'password' },
35
+ dump_tools: DUMP_TOOLS,
33
36
  }
34
37
  end
35
38
 
36
39
  # Compatibility
37
40
  def supported?
38
- @is_supported_rails_version && @dispatcher && %w(mysql mysql2).include?(@activerecord_config['adapter'])
41
+ @is_supported_rails_version && @dispatcher && mysql?
42
+ end
43
+
44
+ # Database
45
+ def mysql?
46
+ dump_tool(:mysqldump) # Just assign DUMP_TOOLS
47
+ %w(mysql mysql2).include?(@activerecord_config['adapter'])
48
+ end
49
+
50
+ # Dump Tool
51
+ def dump_tool(name)
52
+ DUMP_TOOLS[name] ||= `which #{name}`.chomp
53
+ end
54
+
55
+ def dump_tool_installed?(name)
56
+ !dump_tool(name).empty?
39
57
  end
40
58
 
41
59
  # Dispatcher
@@ -1,3 +1,3 @@
1
1
  module Dumper
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-29 00:00:00.000000000 Z
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json