piper-ruby 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -20,8 +20,16 @@ This Piper client support publishing on [NATS](http://nats.io) as a means of
20
20
  delivery if the NATS gem is installed. A flag is also provided to control which
21
21
  method is used to deliver log messages to Piper.
22
22
 
23
+ The Piper::Actor module provides methods for receiving and responding to
24
+ JSON messages from tasks in the Piper process flows. The test/simple_actor.rb provides
25
+ an example of how to use the Piper::Actor module functions.
26
+
23
27
  ## Release Notes
24
28
 
29
+ ### Release 1.2.0 - March 20, 2016
30
+
31
+ - Added the Piper::Actor module to support the Piper Push Cache process flows.
32
+
25
33
  ### Release 1.1.2 - December 9, 2015
26
34
 
27
35
  - Removed an extranious 'z' character in the where field.
data/lib/piper.rb CHANGED
@@ -5,3 +5,4 @@ end # Piper
5
5
  require 'piper/version'
6
6
  require 'piper/manager'
7
7
  require 'piper/logrec'
8
+ require 'piper/actor'
@@ -0,0 +1,40 @@
1
+
2
+ require 'oj'
3
+
4
+ module Piper
5
+
6
+ # Piper::Actor module provides a shell for a spawned Piper Push Cache task
7
+ # actor. Piper Push Cache supports process flows where the individual tasks in
8
+ # a flow can be implemented as a separate application that is spawned when it
9
+ # is needed. The spawned application is expected to continue to run and accept
10
+ # input on stdin. Output is over stdout. Both the input and output are JSON
11
+ # strings. This module takes care of the parsing and serialization.
12
+ #
13
+ # The JSON format for input is a JSON object with an 'id' field and a 'rec'
14
+ # field. The output expected is an 'id' field, 'rec' field, and a 'link' field
15
+ # that identifies the link to follow.
16
+ module Actor
17
+
18
+ # Starts a JSON processing loop that reads from $stdin. The proc provided
19
+ # with the call should call ship() to continue on with the processing.
20
+ def self.process()
21
+ Oj::load($stdin, :mode => :strict) { |json|
22
+ begin
23
+ id = json['id']
24
+ rec = json['rec']
25
+ yield(id, rec)
26
+ rescue Exception => e
27
+ ship(id, { 'kind' => 'Error', 'message' => e.message, 'class' => e.class.to_s }, 'error')
28
+ end
29
+ }
30
+ end
31
+
32
+ # Ships or sends a response to the calling task in the Piper Flow.
33
+ def self.ship(id, rec, link)
34
+ $stdout.puts Oj::dump({ 'id' => id, 'rec' => rec, 'link' => link }, :mode => :strict )
35
+ $stdout.flush()
36
+ end
37
+
38
+ end # Actor
39
+ end # Piper
40
+
data/lib/piper/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Piper
2
2
  # Current version of the module.
3
- VERSION = '1.1.2'
3
+ VERSION = '1.2.0'
4
4
  end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $VERBOSE = true
5
+
6
+ $: << File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib')
7
+
8
+ require 'piper'
9
+ require 'oj'
10
+
11
+ # Try executing this file and then typing in the string to the console
12
+ #
13
+ # {"id":"abc","rec":{"kind":"Test", "num":3}}
14
+ #
15
+ # The following should appear on stderr which is used for debugging.
16
+ #
17
+ # received - id: {id} rec: {"kind"=>"Test", "num"=>3, "link"=>"foo"}
18
+ #
19
+ # The response JSON should appear on stdout as:
20
+ #
21
+ # {"id":"abc","rec":{"kind":"Test","num":3,"link":"foo","wall":["I was here."]},"link":"foo"}
22
+ #
23
+ Piper::Actor::process() { |id,rec|
24
+ $stderr.puts "received - id: {id} rec: #{rec}"
25
+
26
+ rec['wall'] = [] if rec['wall'].nil?
27
+ rec['wall'] << "I was here."
28
+
29
+ Piper::Actor::ship(id, rec, rec['link'])
30
+ }
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piper-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Peter Ohler
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
12
+ date: 2016-03-20 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: A Ruby management client to push JSON to Piper Push Cache.
14
15
  email: peter@ohler.com
@@ -17,38 +18,40 @@ extensions: []
17
18
  extra_rdoc_files:
18
19
  - README.md
19
20
  files:
20
- - LICENSE
21
- - README.md
22
- - lib/piper.rb
21
+ - lib/piper/actor.rb
23
22
  - lib/piper/logrec.rb
24
23
  - lib/piper/manager.rb
25
24
  - lib/piper/version.rb
25
+ - lib/piper.rb
26
26
  - test/pipe_test.rb
27
+ - test/simple_actor.rb
28
+ - LICENSE
29
+ - README.md
27
30
  homepage: http://www.piperpushcache.com
28
31
  licenses:
29
32
  - MIT
30
- metadata: {}
31
33
  post_install_message:
32
34
  rdoc_options:
33
- - "--main"
35
+ - --main
34
36
  - README.md
35
37
  require_paths:
36
38
  - lib
37
39
  required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
38
41
  requirements:
39
- - - ">="
42
+ - - ! '>='
40
43
  - !ruby/object:Gem::Version
41
44
  version: '0'
42
45
  required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
43
47
  requirements:
44
- - - ">="
48
+ - - ! '>='
45
49
  - !ruby/object:Gem::Version
46
50
  version: '0'
47
51
  requirements: []
48
52
  rubyforge_project: piper-ruby
49
- rubygems_version: 2.4.5
53
+ rubygems_version: 1.8.23.2
50
54
  signing_key:
51
- specification_version: 4
55
+ specification_version: 3
52
56
  summary: Management client for Piper Push Cache.
53
57
  test_files: []
54
- has_rdoc: true
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 157dbe77d354d635b57c0de330bf66b95a05824e
4
- data.tar.gz: a9a6eba3c8fa827971e4e0822abef32e0267f21b
5
- SHA512:
6
- metadata.gz: c19e72eaa0ec4eb3f8802910406b0b43a8f9f3a3353e43a73611635b6cb223c4085de1b4797edbff7319ab7d69ea94ff71840db83393edd26b313fb875724843
7
- data.tar.gz: 77fa60d4c01db4ec8bc5858edd211deace1499d1ac27cf91608a0293c435f67c9ecefa4c224b786859e4cec27ba9d7a98bdacc65d3b3869ca33e7fb18dd58d10