Class: Cronicle::Client

Inherits:
Object
  • Object
show all
Includes:
Logger::Helper
Defined in:
lib/cronicle/client.rb

Constant Summary collapse

DEFAULTS =
{
  :concurrency => 10,
  :var_dir => '/var/lib/cronicle'
}

Instance Method Summary collapse

Methods included from Logger::Helper

#log

Constructor Details

#initialize(host_list, options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/cronicle/client.rb', line 9

def initialize(host_list, options = {})
  @host_list = host_list
  @options = DEFAULTS.merge(options)
end

Instance Method Details

#apply(file) ⇒ Object



14
15
16
# File 'lib/cronicle/client.rb', line 14

def apply(file)
  walk(file)
end

#cleanupObject



18
19
20
# File 'lib/cronicle/client.rb', line 18

def cleanup
  walk(nil, :cleanup => true)
end

#exec(file, name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cronicle/client.rb', line 22

def exec(file, name)
  name = name.to_s
  jobs = load_file(file)
  jobs_by_host = select_host(jobs, name)

  if jobs_by_host.empty?
    raise "Definition cannot be found: Job `#{name}`"
  end

  parallel_each(jobs_by_host) do |host, jobs_by_user|
    if @options[:ssh_user] and host !~ /@/
      host = @options[:ssh_user] + '@' + host
    end

    run_driver(host) do |driver|
      jobs_by_user.each do |user, jobs|
        driver.execute_job(user, jobs)
      end
    end
  end
end