Class: RCS::Updater::Payload
- Inherits:
-
Object
- Object
- RCS::Updater::Payload
- Defined in:
- lib/rcs-common/updater/payload.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
600
Constants included from Tracer
Instance Attribute Summary collapse
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#return_code ⇒ Object
readonly
Returns the value of attribute return_code.
-
#stored ⇒ Object
readonly
Returns the value of attribute stored.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(payload, options = {}) ⇒ Payload
constructor
A new instance of Payload.
- #ruby? ⇒ Boolean
- #run ⇒ Object
- #runnable? ⇒ Boolean
- #spawn? ⇒ Boolean
- #storable? ⇒ Boolean
- #store ⇒ Object
Methods included from TmpDir
Methods included from Tracer
#thread_name, #trace, #trace_ensure_log_folders, #trace_init, #trace_named_put, #trace_named_remove, #trace_nested_pop, #trace_nested_push, #trace_setup
Constructor Details
#initialize(payload, options = {}) ⇒ Payload
Returns a new instance of Payload.
18 19 20 21 22 23 24 |
# File 'lib/rcs-common/updater/payload.rb', line 18 def initialize(payload, = {}) = @payload = payload @timeout = ['timeout'].to_i @timeout = DEFAULT_TIMEOUT if @timeout <= 0 end |
Instance Attribute Details
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
14 15 16 |
# File 'lib/rcs-common/updater/payload.rb', line 14 def filepath @filepath end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/rcs-common/updater/payload.rb', line 13 def end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
14 15 16 |
# File 'lib/rcs-common/updater/payload.rb', line 14 def output @output end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
13 14 15 |
# File 'lib/rcs-common/updater/payload.rb', line 13 def payload @payload end |
#return_code ⇒ Object (readonly)
Returns the value of attribute return_code.
14 15 16 |
# File 'lib/rcs-common/updater/payload.rb', line 14 def return_code @return_code end |
#stored ⇒ Object (readonly)
Returns the value of attribute stored.
14 15 16 |
# File 'lib/rcs-common/updater/payload.rb', line 14 def stored @stored end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
13 14 15 |
# File 'lib/rcs-common/updater/payload.rb', line 13 def timeout @timeout end |
Instance Method Details
#[](name) ⇒ Object
36 37 38 |
# File 'lib/rcs-common/updater/payload.rb', line 36 def [](name) instance_variable_get("@#{name}") end |
#ruby? ⇒ Boolean
26 |
# File 'lib/rcs-common/updater/payload.rb', line 26 def ruby?; ['ruby']; end |
#run ⇒ Object
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 |
# File 'lib/rcs-common/updater/payload.rb', line 40 def run @return_code = nil @output = "" cmd = "#{'ruby ' if ruby?}#{storable? ? filepath : payload}" if spawn? trace(:debug, "[spawn] #{cmd}") return spawn(cmd) end Timeout::timeout(@timeout) do trace(:debug, "Timeout has been set to #{@timeout} sec") if @timeout != DEFAULT_TIMEOUT trace(:debug, "[popen] #{cmd}") Open3.popen2e(cmd) do |stdin, std_out_err, wait_thr| while line = std_out_err.gets trace(:debug, "[std_out_err] #{line.strip}") @output << line end @return_code = wait_thr.value.exitstatus end end return @return_code ensure FileUtils.rm_f(filepath) if stored end |
#runnable? ⇒ Boolean
32 33 34 |
# File 'lib/rcs-common/updater/payload.rb', line 32 def runnable? ['exec'] or ruby? or spawn? end |
#spawn? ⇒ Boolean
30 |
# File 'lib/rcs-common/updater/payload.rb', line 30 def spawn?; ['spawn']; end |
#storable? ⇒ Boolean
28 |
# File 'lib/rcs-common/updater/payload.rb', line 28 def storable?; ['store']; end |
#store ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/rcs-common/updater/payload.rb', line 70 def store @filepath = "#{tmpdir}/" + (['filename'] || Time.now.to_f.to_s.gsub(".", "")) FileUtils.mkdir_p(tmpdir) trace(:debug, "Storing payload into #{filepath}") File.open(filepath, "wb") { |f| f.write(payload) } @stored = true end |