Module: MiGA::Daemon::Base
- Included in:
- MiGA::Daemon
- Defined in:
- lib/miga/daemon/base.rb
Instance Method Summary collapse
-
#bypass_maintenance? ⇒ Boolean
Should the daemon ignore regular maintenance steps?.
-
#latency ⇒ Object
Returns Integer indicating the number of seconds to sleep between checks.
-
#logfh ⇒ Object
Writing file handler (IO) to the log file.
-
#maxjobs ⇒ Object
Returns Integer indicating the maximum number of concurrent jobs to run.
-
#nodelist ⇒ Object
Returns the path to the list of execution hostnames.
-
#ppn(what = :dataset) ⇒ Object
Returns Integer indicating the number of CPUs per job, in jobs for
what
. -
#runopts(k, v = nil, force = false) ⇒ Object
Set/get #options, where
k
is the Symbol of the option andv
is the value (or nil to use as getter). -
#runopts_for(opt, what) ⇒ Object
Returns the running option
opt
in jobs forwhat
. -
#show_log! ⇒ Object
Display log instead of the progress summary.
-
#show_log? ⇒ Boolean
Display log instead of the progress summary?.
-
#show_summary! ⇒ Object
Display progress summary instead of the log.
-
#shutdown_when_done? ⇒ Boolean
Returns Boolean indicating if the daemon should shutdown when processing is complete.
-
#skip_maintenance ⇒ Object
Returns the number of times maintenance should be skipped before running.
-
#verbosity ⇒ Object
Returns the level of verbosity for the daemon as an Integer, or 1 if unset.
Instance Method Details
#bypass_maintenance? ⇒ Boolean
Should the daemon ignore regular maintenance steps?
83 84 85 |
# File 'lib/miga/daemon/base.rb', line 83 def bypass_maintenance? !!runopts(:bypass_maintenance) end |
#latency ⇒ Object
Returns Integer indicating the number of seconds to sleep between checks
38 39 40 |
# File 'lib/miga/daemon/base.rb', line 38 def latency runopts(:latency) end |
#logfh ⇒ Object
Writing file handler (IO) to the log file
100 101 102 103 104 105 106 |
# File 'lib/miga/daemon/base.rb', line 100 def logfh @logfh ||= nil return $stderr if show_log? return @logfh if @logfh && !@logfh.closed? @logfh = File.open(output_file, 'w') end |
#maxjobs ⇒ Object
Returns Integer indicating the maximum number of concurrent jobs to run
44 45 46 |
# File 'lib/miga/daemon/base.rb', line 44 def maxjobs runopts(:maxjobs) end |
#nodelist ⇒ Object
Returns the path to the list of execution hostnames
50 51 52 |
# File 'lib/miga/daemon/base.rb', line 50 def nodelist runopts(:nodelist) end |
#ppn(what = :dataset) ⇒ Object
Returns Integer indicating the number of CPUs per job, in jobs for what
. See also #runopts_for
70 71 72 |
# File 'lib/miga/daemon/base.rb', line 70 def ppn(what = :dataset) runopts_for(:ppn, what) end |
#runopts(k, v = nil, force = false) ⇒ Object
Set/get #options, where k
is the Symbol of the option and v
is the value (or nil to use as getter). Skips consistency tests if force
. Returns new value.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/miga/daemon/base.rb', line 11 def runopts(k, v = nil, force = false) k = k.to_sym unless v.nil? case k when :latency, :maxjobs, :ppn, :ppn_project, :format_version, :verbosity, :skip_maintenance v = v.to_i if !force && v == 0 && !%i[verbosity skip_maintenance].include?(k) raise "Daemon's #{k} cannot be set to zero" end when :shutdown_when_done, :show_log, :bypass_maintenance v = !!v when :nodelist if v =~ /^\$/ vv = ENV[v.sub('$', '')] or raise "Unset environment variable: #{v}" v = vv end say "Reading node list: #{v}" v = File.readlines(v).map(&:chomp) end @runopts[k] = v end @runopts[k] end |
#runopts_for(opt, what) ⇒ Object
Returns the running option opt
in jobs for what
. what
can be :dataset
or :projects
63 64 65 |
# File 'lib/miga/daemon/base.rb', line 63 def runopts_for(opt, what) runopts(:"#{opt}_#{what}") || runopts(opt) end |
#show_log! ⇒ Object
Display log instead of the progress summary
110 111 112 |
# File 'lib/miga/daemon/base.rb', line 110 def show_log! @runopts[:show_log] = true end |
#show_log? ⇒ Boolean
Display log instead of the progress summary?
122 123 124 |
# File 'lib/miga/daemon/base.rb', line 122 def show_log? @runopts[:show_log] ||= false end |
#show_summary! ⇒ Object
Display progress summary instead of the log
116 117 118 |
# File 'lib/miga/daemon/base.rb', line 116 def show_summary! @runopts[:show_log] = false end |
#shutdown_when_done? ⇒ Boolean
Returns Boolean indicating if the daemon should shutdown when processing is complete
77 78 79 |
# File 'lib/miga/daemon/base.rb', line 77 def shutdown_when_done? !!runopts(:shutdown_when_done) end |
#skip_maintenance ⇒ Object
Returns the number of times maintenance should be skipped before running
56 57 58 |
# File 'lib/miga/daemon/base.rb', line 56 def skip_maintenance runopts(:skip_maintenance) || 0 end |
#verbosity ⇒ Object
Returns the level of verbosity for the daemon as an Integer, or 1 if unset. Verbosity levels are: 0: No output 1: General daemon and job information 2: Same, and indicate when each task is performed (even if nothing happens) 3: Same, and indicate when each loop begins and ends
94 95 96 |
# File 'lib/miga/daemon/base.rb', line 94 def verbosity runopts(:verbosity) || 1 end |