Class: MiGA::Cli::Action::Daemon

Inherits:
MiGA::Cli::Action show all
Defined in:
lib/miga/cli/action/daemon.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
# File 'lib/miga/cli/action/daemon.rb', line 8

def parse_cli
  cli.defaults = { daemon_opts: [], show_log: false }
  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'
    }.each { |k, v| opt.separator sprintf('    %*s%s', -33, k, v) }
    opt.separator ''

    opt.separator 'MiGA options:'
    cli.opt_object(opt, [:project])
    opt.on(
      '--shutdown-when-done',
      'Exit the daemon when all processing is done',
      'Otherwise, it will stay idle awaiting for new data (default)'
    ) { |v| cli[:shutdown_when_done] = v }
    opt.on(
      '--latency INT',
      'Number of seconds the daemon will be sleeping'
    ) { |v| cli[:latency] = v.to_i }
    opt.on(
      '--max-jobs INT',
      'Maximum number of jobs to use simultaneously'
    ) { |v| cli[:maxjobs] = v.to_i }
    opt.on(
      '--node-list PATH',
      'Path to the list of execution hostnames'
    ) { |v| cli[:nodelist] = v }
    opt.on(
      '--ppn INT', Integer,
      'Maximum number of cores to use in a single job'
    ) { |v| cli[:ppn] = v }
    opt.on(
      '--ppn-project INT', Integer,
      'Maximum number of cores to use in project-wide tasks'
    ) { |v| cli[:ppn_project] = v }
    opt.on(
      '--json PATH',
      'Path to a custom daemon definition in json format'
    ) { |v| cli[:json] = v }
    opt.on(
      '--show-log',
      'Display log on advance instead of the progress summary'
    ) { |v| cli[:show_log] = 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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/miga/cli/action/daemon.rb', line 79

def perform
  cli.operation or raise 'Please specify a daemon operation'

  # Cleanup environment
  %w[PROJECT RUNTYPE CORES DATASET].each { |i| ENV[i] = nil }

  # Configure and run daemon
  p = cli.load_project
  d = MiGA::Daemon.new(p, cli[:json])
  dopts = %i[latency maxjobs nodelist ppn ppn_project shutdown_when_done]
  dopts.each { |k| d.runopts(k, cli[k]) }
  d.show_log! if cli[:show_log]
  d.daemon(cli.operation, cli[:daemon_opts])
end