peplum 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39d9ce50f924ae2ba75b9722feab0a00b40d7c18bca14fdfcfe823de5672ef4b
4
- data.tar.gz: 995a13165a99b8dde616ce02fc878876e9ede71b70016f3f08928312cd969566
3
+ metadata.gz: a833d561020be57a98a105e264e6acd79ebe1a93b17de86e7bd3bb7f34bb88a4
4
+ data.tar.gz: f25b64342453bc340139bceea007d2baf8d95115afd5dc890be29413c3210405
5
5
  SHA512:
6
- metadata.gz: 6f5eb468b00c381da6731f52295cce1636875ad4ba19df0494f2c8957e420cd4161599f65faccec22dd3e1238e1dacc2e18242ba4ecf216e5e3cb5686fe98c8a
7
- data.tar.gz: bf11c45c00a5a2d1f028ac028060588448a2dbc342c133bf0ab7526c8fe09585f17eb2624897231b4bc06b40199b6b6fa24c937ec43cf30e2b12a9eee933da1f
6
+ metadata.gz: 0311c9ba56ad671e05146bdbc5449ce5d8c2c533a07e48a8de55e062813b7865624fc400e4fb9b955a156eabc0b16077bcf7ddca45cbf04e7fd3f002aed4bbdb
7
+ data.tar.gz: 3d9b8e8cc3a45a5f73a4466ecef138dfdd459b8655aeb679b54724881c64ab7873ffff9843226e5a0e61c6bcf1a4d06b3a95da56c022702795d988487a1fd08b
@@ -0,0 +1,67 @@
1
+ require 'peplum/core_ext/array'
2
+
3
+ module Peplum
4
+ class Application
5
+ module Payload
6
+
7
+ class Error < Error
8
+ class ImplementationMissing < Error
9
+ end
10
+ end
11
+
12
+ # Run payload against `objects` based on given `options`
13
+ #
14
+ # @param [Array] objects Objects that this worker should process.
15
+ # @param [Hash, NilClass] options Worker options.
16
+ # @abstract
17
+ def run( objects, options )
18
+ fail Error::ImplementationMissing, 'Missing implementation.'
19
+ end
20
+
21
+ # Distribute `objects` into `groups_of` amount of groups, one for each worker.
22
+ #
23
+ # @param [Array] objects All objects that need to be processed.
24
+ # @param [Integer] groups_of Amount of object groups that should be generated.
25
+ #
26
+ # @return [Array<Array<Object>>] `objects` split in `chunks` amount of groups.
27
+ def split( objects, groups_of )
28
+ objects.chunk groups_of
29
+ end
30
+
31
+ # Merge result `data` for reporting.
32
+ #
33
+ # By default provides a generic implementation that merges the values of `Hash`es and `Array`s.
34
+ # If `String`s or `Numeric`s are contained, the Array is returned as is.
35
+ #
36
+ # @param [Array] data Report data from workers.
37
+ # @return [Object] Merged results.
38
+ #
39
+ # @raise [Error::ImplementationMissing] When the data cannot be handled.
40
+ def merge( data )
41
+ case data.first
42
+ when Hash
43
+ f = data.pop
44
+ data.each do |d|
45
+
46
+ if !f.is_a? Hash
47
+ fail Error::ImplementationMissing, 'Missing implementation: Item not a Hash!'
48
+ end
49
+
50
+ f.merge! d
51
+ end
52
+ f
53
+
54
+ when Array
55
+ data.flatten
56
+
57
+ when String, Numeric
58
+ data
59
+
60
+ else
61
+ fail Error::ImplementationMissing, 'Missing implementation.'
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -1,10 +1,11 @@
1
1
  require 'cuboid'
2
2
  require 'json'
3
3
  require 'peplum'
4
- require 'peplum/core_ext/array'
5
4
 
6
5
  module Peplum
7
6
  class Application < Cuboid::Application
7
+ require 'peplum/application/payload'
8
+
8
9
  require 'peplum/application/services/shared_hash'
9
10
  require 'peplum/application/services/scheduler'
10
11
 
@@ -24,7 +25,10 @@ module Peplum
24
25
  end
25
26
  end
26
27
 
28
+ # @return [Cuboid::RPC::Server::Instance::Peers]
27
29
  attr_reader :peers
30
+
31
+ # @return [Cuboid::RPC::Client::Instance]
28
32
  attr_reader :master
29
33
 
30
34
  def initialize(*)
@@ -34,10 +38,6 @@ module Peplum
34
38
  end
35
39
 
36
40
  def run
37
- Raktr.global.on_error do |_, e|
38
- $stderr.puts e
39
- end
40
-
41
41
  options = @options.dup
42
42
  peplum_options = options.delete( 'peplum' )
43
43
  payload_options = options.delete( 'payload' )
@@ -52,20 +52,22 @@ module Peplum
52
52
  end
53
53
  end
54
54
 
55
+ # @return [TrueClass, FalseClass] Are we a worker Instance?
55
56
  def worker?
56
57
  # Has a master?
57
58
  !!@master
58
59
  end
59
60
 
60
- # Implements:
61
- # * `.run` -- Worker; executes its payload against `objects`.
62
- # * `.split` -- Splits given `objects` into groups for each worker.
63
- # * `.merge` -- Merges results from multiple workers.
61
+ # @return [#run, #split, #merge]
62
+ #
63
+ # * `#run` -- Worker; executes its payload against `objects`.
64
+ # * `#split` -- Scheduler; splits given `objects` into groups for each worker.
65
+ # * `#merge` -- Scheduler; merges results from multiple workers.
64
66
  #
65
- # That's all we need to turn any application into a super version of itself.
67
+ # That's all we need to turn any application into a super version of itself.
66
68
  #
67
69
  # @abstract
68
- def payload
70
+ def payload
69
71
  fail Error, 'Missing #payload!'
70
72
  end
71
73
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peplum
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
@@ -34,6 +34,7 @@ files:
34
34
  - bin/.gitkeep
35
35
  - lib/peplum.rb
36
36
  - lib/peplum/application.rb
37
+ - lib/peplum/application/payload.rb
37
38
  - lib/peplum/application/services/scheduler.rb
38
39
  - lib/peplum/application/services/shared_hash.rb
39
40
  - lib/peplum/core_ext/array.rb