peplum 0.2.7 → 0.3.1
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 +4 -4
- data/lib/peplum/application/payload.rb +67 -0
- data/lib/peplum/application.rb +15 -13
- data/lib/peplum/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a833d561020be57a98a105e264e6acd79ebe1a93b17de86e7bd3bb7f34bb88a4
|
4
|
+
data.tar.gz: f25b64342453bc340139bceea007d2baf8d95115afd5dc890be29413c3210405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/peplum/application.rb
CHANGED
@@ -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,21 +52,23 @@ 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
|
-
#
|
61
|
-
#
|
62
|
-
# *
|
63
|
-
# *
|
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
|
-
#
|
67
|
+
# That's all we need to turn any application into a super version of itself.
|
66
68
|
#
|
67
69
|
# @abstract
|
68
|
-
|
69
|
-
fail Error, 'Missing payload
|
70
|
+
def payload
|
71
|
+
fail Error, 'Missing #payload!'
|
70
72
|
end
|
71
73
|
|
72
74
|
def report( data )
|
@@ -89,7 +91,7 @@ module Peplum
|
|
89
91
|
def schedule( peplum_options, payload_options )
|
90
92
|
max_workers = peplum_options.delete('max_workers')
|
91
93
|
objects = peplum_options.delete('objects')
|
92
|
-
groups = payload.
|
94
|
+
groups = payload.split( objects, max_workers )
|
93
95
|
|
94
96
|
# Workload turned out to be less than our maximum allowed instances.
|
95
97
|
# Don't spawn the max if we don't have to.
|
data/lib/peplum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peplum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tasos Laskos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cuboid
|
@@ -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
|