Class: MiGA::Cli::Action::Lair

Inherits:
MiGA::Cli::Action show all
Defined in:
lib/miga/cli/action/lair.rb

Constant Summary

Constants included from MiGA

MiGA::CITATION, VERSION, VERSION_DATE, VERSION_NAME

Instance Attribute Summary

Attributes inherited from MiGA::Cli::Action

#cli

Attributes included from MiGA::Common::Net

#remote_connection_uri

Instance Method Summary collapse

Methods inherited from MiGA::Cli::Action

#complete, #empty_action, #initialize, #launch, load, #name

Methods inherited from MiGA

CITATION, CITATION_ARRAY, DEBUG, DEBUG_OFF, DEBUG_ON, DEBUG_TRACE_OFF, DEBUG_TRACE_ON, FULL_VERSION, LONG_VERSION, VERSION, VERSION_DATE, #advance, debug?, debug_trace?, initialized?, #like_io?, #num_suffix, rc_path, #result_files_exist?, #say

Methods included from MiGA::Common::Path

#root_path, #script_path

Methods included from MiGA::Common::Format

#clean_fasta_file, #seqs_length, #tabulate

Methods included from MiGA::Common::Net

#download_file_ftp, #http_request, #known_hosts, #main_server, #net_method, #normalize_encoding, #remote_connection

Methods included from MiGA::Common::SystemCall

#run_cmd, #run_cmd_opts

Constructor Details

This class inherits a constructor from MiGA::Cli::Action

Instance Method Details

#parse_cliObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/miga/cli/action/lair.rb', line 8

def parse_cli
  cli.defaults = { daemon_opts: [] }
  cli.expect_operation = true
  cli.parse do |opt|
    opt.separator 'Available operations:'
    {
      start: 'Start an instance of the application',
      stop: 'Start an instance of the application',
      run: 'Start the application and stay on top',
      status: 'Show status (PID) of application instances',
      list: 'List all daemons and their status',
      terminate: 'Terminate all daemons in the lair and exit'
    }.each { |k, v| opt.separator sprintf('    %*s%s', -33, k, v) }
    opt.separator ''

    opt.separator 'MiGA options:'
    opt.on(
      '-p', '--path PATH',
      '(Mandatory) Path to the directory where the MiGA projects are located'
    ) { |v| cli[:path] = v }
    opt.on(
      '--exclude NAME1,NAME2,NAME3', Array,
      'Exclude these projects (identified by name) from the lair'
    ) { |v| cli[:exclude] = v }
    opt.on(
      '--json PATH',
      'Path to a custom daemon definition in json format'
    ) { |v| cli[:json] = v }
    opt.on(
      '--latency INT', Integer,
      'Time to wait between iterations in seconds, by default: 120'
    ) { |v| cli[:latency] = v }
    opt.on(
      '--wait-for INT', Integer,
      'Time to wait for a daemon to report being alive in seconds',
      'by default: 30'
    ) { |v| cli[:wait_for] = v }
    opt.on(
      '--keep-inactive',
      'If set, daemons are kept alive even when inactive;',
      'i.e., when all tasks are complete'
    ) { |v| cli[:keep_inactive] = v }
    opt.on(
      '--no-trust-timestamp',
      'Check all results instead of trusting project timestamps'
    ) { |v| cli[:trust_timestamp] = v }
    opt.on(
      '--name STRING',
      'A name for the chief daemon process'
    ) { |v| cli[:name] = v }
    opt.on(
      '--dry',
      'Report when daemons would be launched, but don\'t actually launch them'
    ) { |v| cli[:dry] = v }
    cli.opt_common(opt)

    opt.separator 'Daemon options:'
    opt.on(
      '-t', '--ontop',
      'Stay on top (does not daemonize)'
    ) { cli[:daemon_opts] << '-t' }
    opt.on(
      '-f', '--force',
      'Force operation'
    ) { cli[:daemon_opts] << '-f' }
    opt.on(
      '-n', '--no_wait',
      'Do not wait for processes to stop'
    ) { cli[:daemon_opts] << '-n' }
    opt.on(
      '--shush',
      'Silence the daemon'
    ) { cli[:daemon_opts] << '--shush' }
    opt.separator ''
  end
end

#performObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/miga/cli/action/lair.rb', line 85

def perform
  cli.ensure_par(path: '-p')
  k_opts = %i[
    json latency wait_for keep_inactive trust_timestamp name dry exclude
  ]
  opts = Hash[k_opts.map { |k| [k, cli[k]] }]
  lair = MiGA::Lair.new(cli[:path], opts)

  case cli.operation.to_sym
  when :terminate
    lair.terminate_daemons
  when :list
    o = []
    lair.each_daemon do |d|
      o << [d.daemon_name, d.class, d.daemon_home, d.active?, d.last_alive]
    end
    cli.table(%w[name class path active last_alive], o)
  else
    lair.daemon(cli.operation, cli[:daemon_opts])
  end
end