Class: Nodectl::Action
Constant Summary
Constants inherited from Process
Process::ENV_BLACKLIST, Process::TIMEOUT
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Attributes inherited from Process
Class Method Summary collapse
- .onkill(&blk) ⇒ Object
- .onkill_call(action, options = {}) ⇒ Object
- .run(service, name, *args, &blk) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(service, name, options = {}, &blk) ⇒ Action
constructor
A new instance of Action.
- #run ⇒ Object
Methods inherited from Process
#alive?, #dead!, #oncrash, #onkill, #onstop, #restart, #stop
Constructor Details
#initialize(service, name, options = {}, &blk) ⇒ Action
Returns a new instance of Action.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/nodectl/action.rb', line 9 def initialize(service, name, = {}, &blk) super(, &blk) @id = Nodectl::Action.next_id @service = service @name = name onkill do result = if @exit_status == 0 "succeed" else "failed" end self.class.onkill_call(self, reason: result) end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/nodectl/action.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/nodectl/action.rb', line 6 def name @name end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
7 8 9 |
# File 'lib/nodectl/action.rb', line 7 def output @output end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
5 6 7 |
# File 'lib/nodectl/action.rb', line 5 def service @service end |
Class Method Details
.onkill(&blk) ⇒ Object
65 66 67 68 |
# File 'lib/nodectl/action.rb', line 65 def onkill(&blk) @onkill ||= [] @onkill << blk end |
.onkill_call(action, options = {}) ⇒ Object
70 71 72 |
# File 'lib/nodectl/action.rb', line 70 def onkill_call(action, = {}) @onkill.each { |b| b.call(action, ) } end |
.run(service, name, *args, &blk) ⇒ Object
74 75 76 77 78 |
# File 'lib/nodectl/action.rb', line 74 def run(service, name, *args, &blk) action = new(service, name, *args, &blk) action.run action end |
Instance Method Details
#as_json ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nodectl/action.rb', line 40 def as_json { "id" => @id, "pid" => @pid, "name" => @name, "service_id" => @service.name, "ws" => "/actions/#{id}", "exit_status" => @exit_status, "started_at" => @started_at.iso8601 } end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nodectl/action.rb', line 27 def run rout, @wout = IO.pipe @output = Nodectl::Stream::FileWithMemory.new(rout) super @started_at = Time.now Nodectl::Action[@id] = self Nodectl.logger.info("action: [#{pid}] started: #{service.name}##{name}") end |