peplum 0.1.0 → 0.2.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: 6624c27866af54f4e3ab25e39a1fedb7ce83039b56c3bf6f43e5be42b19b0025
4
- data.tar.gz: 8895326c25f1745c2074495e4a7666b2055a6e9efd765f90f32135f856c4e4d6
3
+ metadata.gz: 684acaeb0eb2b2cccf49d9959482b56da2a73cf6da28d5c6f34833c015a889be
4
+ data.tar.gz: 5fb7a928493b17e94abb647f5779dd79671df3443d6bc1cc5063e1ee54f196e1
5
5
  SHA512:
6
- metadata.gz: aa10f79c3ce4553d8237da0b0efec0578b2419e3794cefb75f036173acb5c6dfb76f34e743c150c60f919351699e4978944faa01535ed0b89bc7864232abf14a
7
- data.tar.gz: bc66f042bb08248ec3c13ba01b4aea90c80e56ec50016b74e7f38e77b965a40c4745983ed470699ac897ce89df742295a0cbe675006e247719913c8fc18086ed
6
+ metadata.gz: 12ae57302cc03176c3e760f0d3ffece96216dfdf70bb006c758a63c661f10a57aa71abca25a8560028cfacff3f87c95611eed882d50a63e6867fe8bb8471531d
7
+ data.tar.gz: 2066cd3a32f3b4e2ba294c553b406ad32ea54c7bba34a0f38f9cc7c66addf5358e57127aec01eb2c271ff4e51f0f1b2a4259410286a09a77ec414dcd3726a6d8
@@ -5,7 +5,8 @@ module Services
5
5
  class SharedHash
6
6
 
7
7
  def initialize
8
- @hash = {}
8
+ @hash = {}
9
+ @sync_counter = 0
9
10
  end
10
11
 
11
12
  def get( k )
@@ -22,7 +23,8 @@ class SharedHash
22
23
 
23
24
  if broadcast
24
25
  each_peer do |peer|
25
- peer.shared_hash.set( k, v, false ) {}
26
+ @sync_counter += 1
27
+ peer.shared_hash.set( k, v, false ) { @sync_counter -= 1 }
26
28
  end
27
29
  end
28
30
 
@@ -40,7 +42,8 @@ class SharedHash
40
42
 
41
43
  if broadcast
42
44
  each_peer do |_, peer|
43
- peer.shared_hash.delete( k, false ) {}
45
+ @sync_counter += 1
46
+ peer.shared_hash.delete( k, false ) { @sync_counter -= 1 }
44
47
  end
45
48
  end
46
49
 
@@ -52,6 +55,10 @@ class SharedHash
52
55
  @hash.dup
53
56
  end
54
57
 
58
+ def sync
59
+ sleep 0.1 while @sync_counter != 0
60
+ end
61
+
55
62
  private
56
63
 
57
64
  def each_peer( &block )
@@ -41,15 +41,15 @@ module Peplum
41
41
 
42
42
  options = @options.dup
43
43
  peplum_options = options.delete( 'peplum' )
44
- native_options = options.delete( 'native' )
44
+ payload_options = options.delete( 'payload' )
45
45
 
46
46
  # We have a master so we're not the scheduler, run the payload.
47
47
  if peplum_options['master']
48
- execute( peplum_options, native_options )
48
+ execute( peplum_options, payload_options )
49
49
 
50
50
  # We're the scheduler Instance, get to grouping and spawning.
51
51
  else
52
- schedule( peplum_options, native_options )
52
+ schedule( peplum_options, payload_options )
53
53
  end
54
54
  end
55
55
 
@@ -61,31 +61,31 @@ module Peplum
61
61
  # That's all we need to turn any application into a super version of itself.
62
62
  #
63
63
  # @abstract
64
- def native_app
65
- fail Error, 'Missing native app!'
64
+ def payload
65
+ fail Error, 'Missing payload app!'
66
66
  end
67
67
 
68
68
  def report( data )
69
- super native_app.merge( data )
69
+ super payload.merge( data )
70
70
  end
71
71
 
72
72
  private
73
73
 
74
- def execute( peplum_options, native_options )
74
+ def execute( peplum_options, payload_options )
75
75
  master_info = peplum_options.delete( 'master' )
76
76
 
77
77
  self.peers.set( peplum_options.delete( 'peers' ) || {} )
78
78
 
79
- report_data = native_app.run( peplum_options['objects'], native_options )
79
+ report_data = payload.run( peplum_options['objects'], payload_options )
80
80
 
81
81
  master = Processes::Instances.connect( master_info['url'], master_info['token'] )
82
82
  master.scheduler.report report_data, Cuboid::Options.rpc.url
83
83
  end
84
84
 
85
- def schedule( peplum_options, native_options )
85
+ def schedule( peplum_options, payload_options )
86
86
  max_workers = peplum_options.delete('max_workers')
87
87
  objects = peplum_options.delete('objects')
88
- groups = native_app.group( objects, max_workers )
88
+ groups = payload.group( objects, max_workers )
89
89
 
90
90
  # Workload turned out to be less than our maximum allowed instances.
91
91
  # Don't spawn the max if we don't have to.
@@ -110,7 +110,7 @@ module Peplum
110
110
  # We couldn't get the workers we were going for, Grid reached its capacity,
111
111
  # re-balance distribution.
112
112
  if scheduler.workers.size < groups.size
113
- groups = native_app.group( objects, scheduler.workers.size )
113
+ groups = payload.group( objects, scheduler.workers.size )
114
114
  end
115
115
 
116
116
  peers = Hash[scheduler.workers.values.map { |client| [client.url, client.token] }]
@@ -125,7 +125,7 @@ module Peplum
125
125
  token: Cuboid::Options.datastore.token
126
126
  }
127
127
  },
128
- native: native_options
128
+ payload: payload_options
129
129
  )
130
130
  end
131
131
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peplum
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.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.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos