Class: Docker_Rsync::SyncManager
- Inherits:
-
Object
- Object
- Docker_Rsync::SyncManager
- Includes:
- Thor::Shell
- Defined in:
- lib/docker_sync/sync_manager.rb
Instance Method Summary collapse
- #clean(sync_name = nil) ⇒ Object
- #create_sync(sync_name, sync_configuration) ⇒ Object
- #get_sync_points ⇒ Object
- #init_sync_processes(sync_name = nil) ⇒ Object
-
#initialize(options) ⇒ SyncManager
constructor
A new instance of SyncManager.
- #join_threads ⇒ Object
- #load_configuration ⇒ Object
- #run(sync_name = nil) ⇒ Object
- #stop ⇒ Object
- #sync(sync_name = nil) ⇒ Object
- #upgrade_syncs_config ⇒ Object
- #validate_config(config) ⇒ Object
- #validate_sync_config(name, sync_config) ⇒ Object
Constructor Details
#initialize(options) ⇒ SyncManager
Returns a new instance of SyncManager.
16 17 18 19 20 21 22 23 |
# File 'lib/docker_sync/sync_manager.rb', line 16 def initialize() @sync_processes = [] @config_syncs = [] @config_options = [] @config_syncs = [] @config_path = [:config_path] load_configuration end |
Instance Method Details
#clean(sync_name = nil) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/docker_sync/sync_manager.rb', line 86 def clean(sync_name = nil) init_sync_processes(sync_name) @sync_processes.each { |sync_process| sync_process.clean } end |
#create_sync(sync_name, sync_configuration) ⇒ Object
126 127 128 129 |
# File 'lib/docker_sync/sync_manager.rb', line 126 def create_sync(sync_name, sync_configuration) sync_process = Docker_Sync::SyncProcess.new(sync_name, sync_configuration) return sync_process end |
#get_sync_points ⇒ Object
37 38 39 |
# File 'lib/docker_sync/sync_manager.rb', line 37 def get_sync_points return @config_syncs end |
#init_sync_processes(sync_name = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/docker_sync/sync_manager.rb', line 72 def init_sync_processes(sync_name = nil) if sync_name.nil? @config_syncs.each { |name, sync_configuration| @sync_processes.push(create_sync(name, sync_configuration)) } else unless @config_syncs.key?(sync_name) raise("Could not find sync configuration with name #{sync_name}") end @sync_processes.push(create_sync(sync_name, @config_syncs[sync_name])) end end |
#join_threads ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/docker_sync/sync_manager.rb', line 108 def join_threads begin @sync_processes.each do |sync_process| sync_process.watch_thread.join end rescue SystemExit, Interrupt say_status 'shutdown', 'Shutting down...', :blue @sync_processes.each do |sync_process| sync_process.stop end rescue Exception => e puts "EXCEPTION: #{e.inspect}" puts "MESSAGE: #{e.}" end end |
#load_configuration ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/docker_sync/sync_manager.rb', line 25 def load_configuration unless File.exist?(@config_path) raise "Config could not be loaded from #{@config_path} - it does not exist" end config = YAML.load_file(@config_path) validate_config(config) @config_options = config['options'] || {} @config_syncs = config['syncs'] upgrade_syncs_config end |
#run(sync_name = nil) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/docker_sync/sync_manager.rb', line 100 def run(sync_name = nil) init_sync_processes(sync_name) @sync_processes.each { |sync_process| sync_process.run } end |
#stop ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/docker_sync/sync_manager.rb', line 131 def stop @sync_processes.each { |sync_process| sync_process.stop unless sync_process.watch_thread.nil? sync_process.watch_thread.kill end } end |
#sync(sync_name = nil) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/docker_sync/sync_manager.rb', line 93 def sync(sync_name = nil) init_sync_processes(sync_name) @sync_processes.each { |sync_process| sync_process.sync } end |
#upgrade_syncs_config ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/docker_sync/sync_manager.rb', line 41 def upgrade_syncs_config @config_syncs.each do |name, config| @config_syncs[name]['config_path'] = @config_path @config_syncs[name]['src'] = File.(@config_syncs[name]['src']) unless config.key?('verbose') @config_syncs[name]['verbose'] = false if @config_options.key?('verbose') @config_syncs[name]['verbose'] = @config_options['verbose'] end end end end |
#validate_config(config) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/docker_sync/sync_manager.rb', line 54 def validate_config(config) unless config.key?('syncs') raise ('no syncs defined') end config['syncs'].each do |name, sync_config| validate_sync_config(name, sync_config) end return true end |
#validate_sync_config(name, sync_config) ⇒ Object
66 67 68 69 70 |
# File 'lib/docker_sync/sync_manager.rb', line 66 def validate_sync_config(name, sync_config) %w[src dest sync_host_port].each do |key| raise ("#{name} does not have #{key} condiguration value set - this is mandatory") unless sync_config.key?(key) end end |