Module: Piper::Actor
- Defined in:
- lib/piper/actor.rb
Overview
Piper::Actor module provides a shell for a spawned Piper Push Cache task actor. Piper Push Cache supports process flows where the individual tasks in a flow can be implemented as a separate application that is spawned when it is needed. The spawned application is expected to continue to run and accept input on stdin. Output is over stdout. Both the input and output are JSON strings. This module takes care of the parsing and serialization.
The JSON format for input is a JSON object with an ‘id’ field and a ‘rec’ field. The output expected is an ‘id’ field, ‘rec’ field, and a ‘link’ field that identifies the link to follow.
Class Method Summary collapse
-
.process ⇒ Object
Starts a JSON processing loop that reads from $stdin.
-
.ship(id, rec, link) ⇒ Object
Ships or sends a response to the calling task in the Piper Flow.
Class Method Details
.process ⇒ Object
Starts a JSON processing loop that reads from $stdin. The proc provided with the call should call ship() to continue on with the processing.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/piper/actor.rb', line 20 def self.process() begin Oj::load($stdin, :mode => :strict) { |json| begin id = json['id'] rec = json['rec'] yield(id, rec) rescue Exception => e ship(id, { 'kind' => 'Error', 'message' => e., 'class' => e.class.to_s }, 'error') end } rescue Interrupt # ^C or parent went away end end |
.ship(id, rec, link) ⇒ Object
Ships or sends a response to the calling task in the Piper Flow.
37 38 39 40 |
# File 'lib/piper/actor.rb', line 37 def self.ship(id, rec, link) $stdout.puts Oj::dump({ 'id' => id, 'rec' => rec, 'link' => link }, :mode => :strict ) $stdout.flush() end |