peplum 0.3.1 → 0.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a833d561020be57a98a105e264e6acd79ebe1a93b17de86e7bd3bb7f34bb88a4
4
- data.tar.gz: f25b64342453bc340139bceea007d2baf8d95115afd5dc890be29413c3210405
3
+ metadata.gz: 427efea5fb0daf113212ee723e2e850ccb30723af7e7d5c6ea3576fe9e51979e
4
+ data.tar.gz: f6563c4ac916f06e66bba1d7ba6d69fed7818b601d9148d5d111dc7c6756d1d3
5
5
  SHA512:
6
- metadata.gz: 0311c9ba56ad671e05146bdbc5449ce5d8c2c533a07e48a8de55e062813b7865624fc400e4fb9b955a156eabc0b16077bcf7ddca45cbf04e7fd3f002aed4bbdb
7
- data.tar.gz: 3d9b8e8cc3a45a5f73a4466ecef138dfdd459b8655aeb679b54724881c64ab7873ffff9843226e5a0e61c6bcf1a4d06b3a95da56c022702795d988487a1fd08b
6
+ metadata.gz: ecb729393728b371af870f5615a00e6d815e773932aefedce3aefa4e07e20f82eb2dbd0bee40e99add29f2a1b915654115c74df3cfb11427f87507cc4d85e584
7
+ data.tar.gz: 5d8ea07c8ccbac15dc63116d377b4259662634f75b105b77223b6805ded8e5176e0bbc292d67cc1a9d7768929e7c3045d16925c7b1e239c884dcb10bdead0664
@@ -0,0 +1,19 @@
1
+ module Peplum
2
+ class Application
3
+
4
+ module Worker
5
+
6
+ # @return [Cuboid::RPC::Server::Instance::Peers]
7
+ attr_reader :peers
8
+
9
+ # @return [Cuboid::RPC::Client::Instance, NilClass]
10
+ attr_reader :scheduler
11
+
12
+ def peers
13
+ @peers ||= Cuboid::RPC::Server::Instance::Peers.new
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -4,60 +4,54 @@ require 'peplum'
4
4
 
5
5
  module Peplum
6
6
  class Application < Cuboid::Application
7
+ require 'peplum/application/worker'
7
8
  require 'peplum/application/payload'
8
9
 
9
10
  require 'peplum/application/services/shared_hash'
10
11
  require 'peplum/application/services/scheduler'
11
12
 
12
- class Error < Peplum::Error; end
13
+ class Error < Peplum::Error
14
+ class PayloadMissing < Error
15
+ end
16
+ end
13
17
 
18
+ # Hijack Cuboid to set ourselves up.
14
19
  class <<self
15
20
  def inherited( application )
16
21
  super
17
22
 
23
+ # Don't trust Cuboid's auto-detection for this, make sure the inheriting class is the Cuboid application.
18
24
  Cuboid::Application.application = application
19
25
 
20
26
  application.validate_options_with :validate_options
21
- application.serialize_with JSON
27
+ application.serialize_with MessagePack
22
28
 
23
29
  application.instance_service_for :scheduler, Services::Scheduler
30
+
31
+ # Shared, in-memory key-value store for the workers, the scheduler will not be participate.
24
32
  application.instance_service_for :shared_hash, Services::SharedHash
25
33
  end
26
34
  end
27
35
 
28
- # @return [Cuboid::RPC::Server::Instance::Peers]
29
- attr_reader :peers
30
-
31
- # @return [Cuboid::RPC::Client::Instance]
32
- attr_reader :master
33
-
34
- def initialize(*)
35
- super
36
-
37
- @peers = Cuboid::RPC::Server::Instance::Peers.new
38
- end
39
-
40
36
  def run
41
37
  options = @options.dup
38
+
39
+ # System options.
42
40
  peplum_options = options.delete( 'peplum' )
41
+
42
+ # Payload options.
43
43
  payload_options = options.delete( 'payload' )
44
44
 
45
- # We have a master so we're not the scheduler, run the payload.
45
+ # We have a master so we're a worker, run the payload.
46
46
  if peplum_options['master']
47
- execute( peplum_options, payload_options )
47
+ work( peplum_options, payload_options )
48
48
 
49
- # We're the scheduler Instance, get to grouping and spawning.
49
+ # We're the scheduler Instance, get to grouping objects and spawning workers.
50
50
  else
51
51
  schedule( peplum_options, payload_options )
52
52
  end
53
53
  end
54
54
 
55
- # @return [TrueClass, FalseClass] Are we a worker Instance?
56
- def worker?
57
- # Has a master?
58
- !!@master
59
- end
60
-
61
55
  # @return [#run, #split, #merge]
62
56
  #
63
57
  # * `#run` -- Worker; executes its payload against `objects`.
@@ -68,23 +62,32 @@ module Peplum
68
62
  #
69
63
  # @abstract
70
64
  def payload
71
- fail Error, 'Missing #payload!'
65
+ fail Error::PayloadMissing, 'Missing #payload implementation!'
72
66
  end
73
67
 
68
+ # Overload {Cuboid#report} and delegate to the {Payload.merge} prior passing it on to {Cuboid}.
69
+ # @private
74
70
  def report( data )
75
71
  super payload.merge( data )
76
72
  end
77
73
 
78
74
  private
79
75
 
80
- def execute( peplum_options, payload_options )
76
+ def work( peplum_options, payload_options )
77
+ # We're now a worker class!
78
+ self.class.include Worker
79
+
81
80
  master_info = peplum_options.delete( 'master' )
82
81
  @master = Processes::Instances.connect( master_info['url'], master_info['token'] )
83
82
 
83
+ # Configure us to know the rest of our worker peers.
84
+ # Required for the SharedHash service.
84
85
  self.peers.set( peplum_options.delete( 'peers' ) || {} )
85
86
 
87
+ # Deliver the payload.
86
88
  report_data = payload.run( peplum_options['objects'], payload_options )
87
89
 
90
+ # Signal that we're done by passing our report to the scheduler.
88
91
  @master.scheduler.report report_data, Cuboid::Options.rpc.url
89
92
  end
90
93
 
@@ -153,9 +156,20 @@ module Peplum
153
156
  fail Error, 'Options: Missing :max_workers'
154
157
  end
155
158
 
159
+ validate_payload
160
+
156
161
  @options = options
157
162
  true
158
163
  end
159
164
 
165
+ def validate_payload
166
+ p = self.payload
167
+
168
+ %w(run merge split).each do |m|
169
+ next if p.respond_to? m
170
+ fail Payload::Error::ImplementationMissing, "#{payload} missing implementation for: ##{m}"
171
+ end
172
+ end
173
+
160
174
  end
161
175
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peplum
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peplum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
@@ -37,6 +37,7 @@ files:
37
37
  - lib/peplum/application/payload.rb
38
38
  - lib/peplum/application/services/scheduler.rb
39
39
  - lib/peplum/application/services/shared_hash.rb
40
+ - lib/peplum/application/worker.rb
40
41
  - lib/peplum/core_ext/array.rb
41
42
  - lib/peplum/version.rb
42
43
  - peplum.gemspec