zold 0.13.14 → 0.13.15

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
  SHA1:
3
- metadata.gz: 4bd17544e10ae8e3e44b31728baa5a7c81f95897
4
- data.tar.gz: 6aaef2eb60f229ff5fa3b5e0b83af513fda3400b
3
+ metadata.gz: ee79ed1a6d5050ca1df7ced93d9bf5f2b488c160
4
+ data.tar.gz: 1a01a16eaa9006a2c82a7142d918d3acddf24e7d
5
5
  SHA512:
6
- metadata.gz: ae727ac0ae0d521b7d0f71fa2a9b77bb5893e3ee615c691f92a4af73941fb678b3c504d592cb96e06229ce208868dc8f34a61bd80fe3630ff233500cabe01786
7
- data.tar.gz: d6ed3bcd815087a4bafed60d91ff54a2e143cc0222a3ca6feb4e65b5e03d11cd9a4b58d31d78d69c21c579218aa953277723d81764b01e429ea011ca0cf3a077
6
+ metadata.gz: 6aac2cf9156a6c3439a610419256a4f5a2c4f19dc0a594b29b29b10a816a5eacaf5ea1406b8f5631af384dc0fbeb5395bb9533242c6d033630787a8f2a5c07b8
7
+ data.tar.gz: 72c085b6d56e2f19340906c3d106079f406c33709b5bdb47ea40b3e1151f1e0fb91ca92ada87869e482f32eb221f675090cbe56a503f3fc101218c52919d2536
@@ -158,7 +158,7 @@ module Zold
158
158
  threads: opts[:threads], strength: opts[:strength]
159
159
  )
160
160
  Front.set(:farm, farm)
161
- metronome = metronome(farm, opts)
161
+ metronome = metronome(farm, entrance, opts)
162
162
  begin
163
163
  @log.info("Starting up the web front at http://#{opts[:host]}:#{opts[:port]}...")
164
164
  Front.run!
@@ -217,8 +217,10 @@ module Zold
217
217
  pid
218
218
  end
219
219
 
220
- def metronome(farm, opts)
220
+ def metronome(farm, entrance, opts)
221
221
  metronome = Metronome.new(@log)
222
+ require_relative 'routines/spread'
223
+ metronome.add(Routines::Spread.new(opts, @wallets, entrance, log: @log))
222
224
  unless opts[:standalone]
223
225
  require_relative 'routines/reconnect'
224
226
  metronome.add(Routines::Reconnect.new(opts, @remotes, farm, log: @log))
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2018 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative '../remote'
22
+ require_relative '../pull'
23
+ require_relative '../pay'
24
+ require_relative '../push'
25
+
26
+ # Spread random wallets to the network.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
29
+ # License:: MIT
30
+ module Zold
31
+ # Routines module
32
+ module Routines
33
+ # Spread them
34
+ class Spread
35
+ def initialize(opts, wallets, entrance, log: Log::Quiet.new)
36
+ @opts = opts
37
+ @wallets = wallets
38
+ @entrance = entrance
39
+ @log = log
40
+ end
41
+
42
+ def exec(_ = 0)
43
+ sleep(60) unless @opts['routine-immediately']
44
+ @entrance.spread(@wallets.all.sample(10).map { |w| Id.new(w) })
45
+ end
46
+ end
47
+ end
48
+ end
@@ -97,6 +97,12 @@ module Zold
97
97
  end
98
98
  end
99
99
 
100
+ def spread(ids)
101
+ return if ids.empty?
102
+ @push_mutex.synchronize { @modified += ids }
103
+ @pushes.post { push_one } if @pushes.length < 2
104
+ end
105
+
100
106
  private
101
107
 
102
108
  # Returns a list of modifed wallets (as Zold::Id)
@@ -128,10 +134,7 @@ and modified nothing (this is most likely a bug!)")
128
134
  ).run(['merge', id.to_s])
129
135
  Clean.new(wallets: @wallets, copies: copies.root, log: @log).run(['clean', id.to_s])
130
136
  copies.remove(localhost, Remotes::PORT)
131
- unless modified.empty?
132
- @push_mutex.synchronize { @modified += modified }
133
- @pushes.post { push_one } if @pushes.length < 2
134
- end
137
+ spread(modified)
135
138
  modified
136
139
  end
137
140
 
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.13.14'.freeze
26
+ VERSION = '0.13.15'.freeze
27
27
  end
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2018 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'minitest/autorun'
22
+ require 'webmock/minitest'
23
+ require_relative '../../test__helper'
24
+ require_relative '../../fake_home'
25
+ require_relative '../../node/fake_node'
26
+ require_relative '../../../lib/zold/commands/routines/spread.rb'
27
+
28
+ # Spread test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestSpread < Minitest::Test
33
+ def test_spread_wallets
34
+ FakeHome.new.run do |home|
35
+ 5.times { home.create_wallet }
36
+ opts = {
37
+ 'routine-immediately' => true
38
+ }
39
+ entrance = Zold::Entrance.new(
40
+ home.wallets, home.remotes, home.copies(home.create_wallet).root, 'x', log: test_log
41
+ )
42
+ Zold::Routines::Spread.new(opts, home.wallets, entrance, log: test_log).exec
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.14
4
+ version: 0.13.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -354,6 +354,7 @@ files:
354
354
  - lib/zold/commands/remote.rb
355
355
  - lib/zold/commands/routines/bonuses.rb
356
356
  - lib/zold/commands/routines/reconnect.rb
357
+ - lib/zold/commands/routines/spread.rb
357
358
  - lib/zold/commands/show.rb
358
359
  - lib/zold/commands/taxes.rb
359
360
  - lib/zold/copies.rb
@@ -381,6 +382,7 @@ files:
381
382
  - resources/remotes
382
383
  - test/commands/routines/test_bonuses.rb
383
384
  - test/commands/routines/test_reconnect.rb
385
+ - test/commands/routines/test_spread.rb
384
386
  - test/commands/test_calculate.rb
385
387
  - test/commands/test_clean.rb
386
388
  - test/commands/test_create.rb
@@ -455,6 +457,7 @@ test_files:
455
457
  - features/support/env.rb
456
458
  - test/commands/routines/test_bonuses.rb
457
459
  - test/commands/routines/test_reconnect.rb
460
+ - test/commands/routines/test_spread.rb
458
461
  - test/commands/test_calculate.rb
459
462
  - test/commands/test_clean.rb
460
463
  - test/commands/test_create.rb