parallel_minion 1.3.0 → 1.4.0
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/README.md +11 -3
- data/Rakefile +10 -10
- data/lib/parallel_minion/minion.rb +14 -11
- data/lib/parallel_minion/railtie.rb +2 -2
- data/lib/parallel_minion/version.rb +1 -1
- data/lib/parallel_minion.rb +3 -3
- metadata +7 -23
- data/test/config/database.yml +0 -5
- data/test/minion_scope_test.rb +0 -58
- data/test/minion_test.rb +0 -245
- data/test/test_db.sqlite3 +0 -0
- data/test/test_helper.rb +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ee831ee7f2939c246ff997e0abbdeca9f2779a4faa21d68d1cd6d4e27c09b52
|
|
4
|
+
data.tar.gz: e681733d3cbd2e9da49a0552e070a9fa52be776208d2bbfa02943752fd3b6a53
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa0986ec9d4c9c8713f9a19a37ba32739af5c184fd558e1ce9860a2b38de5caf6ccb8aa1a933fb4969f9ca94224a21386fd608551b6d582d0e2418976b9c26c6
|
|
7
|
+
data.tar.gz: 8d7b3ca45414d9154311fed2fa3d7ab487f201224532e07304c1f8965265d0d8bb96a44da10aa4b82b940869df0c60c3e91e1fbd43390f0595cc91a6aef716e8
|
data/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# Parallel Minion
|
|
2
|
+
[](https://rubygems.org/gems/parallel_minion) [](https://github.com/reidmorrison/parallel_minion/actions?query=workflow%3Abuild) [](https://rubygems.org/gems/parallel_minion) [](http://opensource.org/licenses/Apache-2.0) 
|
|
3
3
|
|
|
4
4
|
Wrap Ruby code with a minion so that it is run on a parallel thread.
|
|
5
5
|
|
|
@@ -46,12 +46,20 @@ has been achieved by moving existing blocks of code into Minions.
|
|
|
46
46
|
|
|
47
47
|
gem install parallel_minion
|
|
48
48
|
|
|
49
|
+
## Rails 7.2 compatibility
|
|
50
|
+
|
|
51
|
+
- **Apps** need **Ruby ≥ 3.1** (Rails 7.2 requirement).
|
|
52
|
+
- **Code:** Thread cleanup uses `ActiveRecord::Base.connection_handler.clear_active_connections!` instead of `ActiveRecord::Base.clear_active_connections!` because Rails 7 deprecates the latter.
|
|
53
|
+
- **Railtie:** Unchanged (`config.parallel_minion` as before).
|
|
54
|
+
- **CI:** `rails_7.2` Appraisal `gemfiles/rails_7.2.gemfile`, Ruby 3.2. The 7.2 appraisal pins **Minitest ~> 5.0** (tests use `stub`, removed in Minitest 6).
|
|
55
|
+
- **sqlite3 (dev):** The 7.2 appraisal allows `sqlite3 >= 1.4` (including 2.x). Other gemfiles use `sqlite3 >= 1.5, < 2` to skip **1.4.4**, which often fails to compile on modern toolchains (all OSes).
|
|
56
|
+
|
|
49
57
|
## Meta
|
|
50
58
|
|
|
51
59
|
* Code: `git clone git://github.com/reidmorrison/parallel_minion.git`
|
|
52
60
|
* Home: <https://github.com/reidmorrison/parallel_minion>
|
|
53
61
|
* Bugs: <http://github.com/reidmorrison/parallel_minion/issues>
|
|
54
|
-
* Gems: <
|
|
62
|
+
* Gems: <https://rubygems.org/gems/parallel_minion>
|
|
55
63
|
|
|
56
64
|
This project uses [Semantic Versioning](http://semver.org/).
|
|
57
65
|
|
data/Rakefile
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
# Setup bundler to avoid having to run bundle exec all the time.
|
|
2
|
-
require
|
|
3
|
-
require
|
|
2
|
+
require "rubygems"
|
|
3
|
+
require "bundler/setup"
|
|
4
4
|
|
|
5
|
-
require
|
|
6
|
-
require_relative
|
|
5
|
+
require "rake/testtask"
|
|
6
|
+
require_relative "lib/parallel_minion/version"
|
|
7
7
|
|
|
8
8
|
task :gem do
|
|
9
|
-
system
|
|
9
|
+
system "gem build parallel_minion.gemspec"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
task publish: :gem do
|
|
13
|
-
system "git tag -a v#{ParallelMinion::VERSION} -m 'Tagging #{ParallelMinion::VERSION}'"
|
|
14
|
-
system
|
|
13
|
+
# system "git tag -a v#{ParallelMinion::VERSION} -m 'Tagging #{ParallelMinion::VERSION}'"
|
|
14
|
+
# system "git push --tags"
|
|
15
15
|
system "gem push parallel_minion-#{ParallelMinion::VERSION}.gem"
|
|
16
16
|
system "rm parallel_minion-#{ParallelMinion::VERSION}.gem"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
Rake::TestTask.new(:test) do |t|
|
|
20
|
-
t.pattern =
|
|
20
|
+
t.pattern = "test/**/*_test.rb"
|
|
21
21
|
t.verbose = true
|
|
22
22
|
t.warning = false
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
# By default run tests against all appraisals
|
|
26
|
-
if !ENV[
|
|
27
|
-
require
|
|
26
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
|
27
|
+
require "appraisal"
|
|
28
28
|
task default: :appraisal
|
|
29
29
|
else
|
|
30
30
|
task default: :test
|
|
@@ -70,6 +70,7 @@ module ParallelMinion
|
|
|
70
70
|
# :trace, :debug, :info, :warn, :error, :fatal
|
|
71
71
|
def self.started_log_level=(level)
|
|
72
72
|
raise(ArgumentError, "Invalid log level: #{level}") unless SemanticLogger::LEVELS.include?(level)
|
|
73
|
+
|
|
73
74
|
@started_log_level = level
|
|
74
75
|
end
|
|
75
76
|
|
|
@@ -85,6 +86,7 @@ module ParallelMinion
|
|
|
85
86
|
# :trace, :debug, :info, :warn, :error, :fatal
|
|
86
87
|
def self.completed_log_level=(level)
|
|
87
88
|
raise(ArgumentError, "Invalid log level: #{level}") unless SemanticLogger::LEVELS.include?(level)
|
|
89
|
+
|
|
88
90
|
@completed_log_level = level
|
|
89
91
|
end
|
|
90
92
|
|
|
@@ -96,7 +98,6 @@ module ParallelMinion
|
|
|
96
98
|
self.completed_log_level = :info
|
|
97
99
|
self.enabled = true
|
|
98
100
|
self.scoped_classes = []
|
|
99
|
-
logger.name = 'Minion'
|
|
100
101
|
|
|
101
102
|
# Create a new Minion
|
|
102
103
|
#
|
|
@@ -215,7 +216,7 @@ module ParallelMinion
|
|
|
215
216
|
# customer.save!
|
|
216
217
|
# end
|
|
217
218
|
def initialize(*arguments,
|
|
218
|
-
description:
|
|
219
|
+
description: "Minion",
|
|
219
220
|
metric: nil,
|
|
220
221
|
log_exception: nil,
|
|
221
222
|
on_exception_level: self.class.completed_log_level,
|
|
@@ -224,7 +225,8 @@ module ParallelMinion
|
|
|
224
225
|
on_timeout: nil,
|
|
225
226
|
wait_metric: nil,
|
|
226
227
|
&block)
|
|
227
|
-
raise
|
|
228
|
+
raise "Missing mandatory block that Minion must perform" unless block
|
|
229
|
+
|
|
228
230
|
@start_time = Time.now
|
|
229
231
|
@exception = nil
|
|
230
232
|
@arguments = arguments
|
|
@@ -238,10 +240,10 @@ module ParallelMinion
|
|
|
238
240
|
|
|
239
241
|
@wait_metric = (wait_metric || "#{metric}/wait") if @metric
|
|
240
242
|
|
|
241
|
-
# When minion is disabled it
|
|
243
|
+
# When minion is disabled make it obvious in the logs by setting the name to 'Inline' instead of 'Minion'.
|
|
242
244
|
unless @enabled
|
|
243
245
|
l = self.class.logger.dup
|
|
244
|
-
l.name =
|
|
246
|
+
l.name = "Inline"
|
|
245
247
|
self.logger = l
|
|
246
248
|
end
|
|
247
249
|
|
|
@@ -295,7 +297,8 @@ module ParallelMinion
|
|
|
295
297
|
# Returns nil if their is no time limit. I.e. :timeout was set to Minion::INFINITE (infinite time left)
|
|
296
298
|
def time_left
|
|
297
299
|
return nil if timeout.zero? || (timeout == -1)
|
|
298
|
-
|
|
300
|
+
|
|
301
|
+
duration = timeout - ((Time.now - start_time) * 1000)
|
|
299
302
|
duration <= 0 ? 0 : duration
|
|
300
303
|
end
|
|
301
304
|
|
|
@@ -335,8 +338,8 @@ module ParallelMinion
|
|
|
335
338
|
) do
|
|
336
339
|
@result = instance_exec(*arguments, &block)
|
|
337
340
|
end
|
|
338
|
-
rescue Exception =>
|
|
339
|
-
@exception =
|
|
341
|
+
rescue Exception => e
|
|
342
|
+
@exception = e
|
|
340
343
|
ensure
|
|
341
344
|
@duration = Time.now - start_time
|
|
342
345
|
end
|
|
@@ -372,13 +375,13 @@ module ParallelMinion
|
|
|
372
375
|
metric: metric,
|
|
373
376
|
&proc
|
|
374
377
|
)
|
|
375
|
-
rescue Exception =>
|
|
376
|
-
@exception =
|
|
378
|
+
rescue Exception => e
|
|
379
|
+
@exception = e
|
|
377
380
|
nil
|
|
378
381
|
ensure
|
|
379
382
|
@duration = Time.now - start_time
|
|
380
383
|
# Return any database connections used by this thread back to the pool
|
|
381
|
-
ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
|
|
384
|
+
ActiveRecord::Base.connection_handler.clear_active_connections! if defined?(ActiveRecord::Base)
|
|
382
385
|
end
|
|
383
386
|
# rubocop:enable Lint/RescueException
|
|
384
387
|
end
|
data/lib/parallel_minion.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "semantic_logger"
|
|
2
2
|
|
|
3
3
|
module ParallelMinion
|
|
4
|
-
autoload :Minion,
|
|
4
|
+
autoload :Minion, "parallel_minion/minion"
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
require
|
|
7
|
+
require "parallel_minion/railtie" if defined?(Rails)
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: parallel_minion
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Reid Morrison
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: semantic_logger
|
|
@@ -24,9 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '4.0'
|
|
27
|
-
description:
|
|
28
|
-
email:
|
|
29
|
-
- reidmo@gmail.com
|
|
30
26
|
executables: []
|
|
31
27
|
extensions: []
|
|
32
28
|
extra_rdoc_files: []
|
|
@@ -38,16 +34,11 @@ files:
|
|
|
38
34
|
- lib/parallel_minion/minion.rb
|
|
39
35
|
- lib/parallel_minion/railtie.rb
|
|
40
36
|
- lib/parallel_minion/version.rb
|
|
41
|
-
- test/config/database.yml
|
|
42
|
-
- test/minion_scope_test.rb
|
|
43
|
-
- test/minion_test.rb
|
|
44
|
-
- test/test_db.sqlite3
|
|
45
|
-
- test/test_helper.rb
|
|
46
37
|
homepage: https://github.com/reidmorrison/parallel_minion
|
|
47
38
|
licenses:
|
|
48
39
|
- Apache License V2.0
|
|
49
|
-
metadata:
|
|
50
|
-
|
|
40
|
+
metadata:
|
|
41
|
+
rubygems_mfa_required: 'true'
|
|
51
42
|
rdoc_options: []
|
|
52
43
|
require_paths:
|
|
53
44
|
- lib
|
|
@@ -55,21 +46,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
55
46
|
requirements:
|
|
56
47
|
- - ">="
|
|
57
48
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: '2.
|
|
49
|
+
version: '2.5'
|
|
59
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
51
|
requirements:
|
|
61
52
|
- - ">="
|
|
62
53
|
- !ruby/object:Gem::Version
|
|
63
54
|
version: '0'
|
|
64
55
|
requirements: []
|
|
65
|
-
|
|
66
|
-
rubygems_version: 2.7.3
|
|
67
|
-
signing_key:
|
|
56
|
+
rubygems_version: 3.6.9
|
|
68
57
|
specification_version: 4
|
|
69
58
|
summary: Wrap Ruby code with a minion so that it is run on a parallel thread
|
|
70
|
-
test_files:
|
|
71
|
-
- test/minion_test.rb
|
|
72
|
-
- test/minion_scope_test.rb
|
|
73
|
-
- test/config/database.yml
|
|
74
|
-
- test/test_db.sqlite3
|
|
75
|
-
- test/test_helper.rb
|
|
59
|
+
test_files: []
|
data/test/config/database.yml
DELETED
data/test/minion_scope_test.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require_relative 'test_helper'
|
|
2
|
-
require 'erb'
|
|
3
|
-
require 'active_record'
|
|
4
|
-
|
|
5
|
-
ActiveRecord::Base.logger = SemanticLogger[ActiveRecord]
|
|
6
|
-
ActiveRecord::Base.configurations = YAML.safe_load(ERB.new(IO.read('test/config/database.yml')).result)
|
|
7
|
-
ActiveRecord::Base.establish_connection(:test)
|
|
8
|
-
|
|
9
|
-
ActiveRecord::Schema.define version: 0 do
|
|
10
|
-
create_table :people, force: true do |t|
|
|
11
|
-
t.string :name
|
|
12
|
-
t.string :state
|
|
13
|
-
t.string :zip_code
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
class Person < ActiveRecord::Base
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
class MinionScopeTest < Minitest::Test
|
|
21
|
-
describe ParallelMinion::Minion do
|
|
22
|
-
[false, true].each do |enabled|
|
|
23
|
-
describe ".new with enabled: #{enabled.inspect}" do
|
|
24
|
-
before do
|
|
25
|
-
Person.create(name: 'Jack', state: 'FL', zip_code: 38_729)
|
|
26
|
-
Person.create(name: 'John', state: 'FL', zip_code: 35_363)
|
|
27
|
-
Person.create(name: 'Jill', state: 'FL', zip_code: 73_534)
|
|
28
|
-
Person.create(name: 'Joe', state: 'NY', zip_code: 45_325)
|
|
29
|
-
Person.create(name: 'Jane', state: 'NY', zip_code: 45_325)
|
|
30
|
-
Person.create(name: 'James', state: 'CA', zip_code: 123_123)
|
|
31
|
-
# Instruct Minions to adhere to any dynamic scopes for Person model
|
|
32
|
-
ParallelMinion::Minion.scoped_classes << Person
|
|
33
|
-
ParallelMinion::Minion.enabled = enabled
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
after do
|
|
37
|
-
Person.destroy_all
|
|
38
|
-
ParallelMinion::Minion.scoped_classes.clear
|
|
39
|
-
SemanticLogger.flush
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it 'copy across model scope' do
|
|
43
|
-
assert_equal 6, Person.count
|
|
44
|
-
|
|
45
|
-
Person.unscoped.where(state: 'FL').scoping { Person.count }
|
|
46
|
-
|
|
47
|
-
Person.unscoped.where(state: 'FL').scoping do
|
|
48
|
-
assert_equal 3, Person.count
|
|
49
|
-
minion = ParallelMinion::Minion.new(description: 'Scope Test', log_exception: :full) do
|
|
50
|
-
Person.count
|
|
51
|
-
end
|
|
52
|
-
assert_equal 3, minion.result
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
data/test/minion_test.rb
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
require_relative './test_helper'
|
|
2
|
-
|
|
3
|
-
# Test ParallelMinion standalone without Rails
|
|
4
|
-
# Run this test standalone to verify it has no Rails dependencies
|
|
5
|
-
class MinionTest < Minitest::Test
|
|
6
|
-
include SemanticLogger::Loggable
|
|
7
|
-
|
|
8
|
-
describe ParallelMinion::Minion do
|
|
9
|
-
class InMemoryAppender < SemanticLogger::Subscriber
|
|
10
|
-
attr_reader :messages
|
|
11
|
-
|
|
12
|
-
def initialize
|
|
13
|
-
@messages = []
|
|
14
|
-
self.name = 'Minion'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def log(log)
|
|
18
|
-
messages << log.dup
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
let :log_messages do
|
|
23
|
-
appender.messages
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
let :appender do
|
|
27
|
-
InMemoryAppender.new
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
before do
|
|
31
|
-
ParallelMinion::Minion.logger = appender
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
[false, true].each do |enabled|
|
|
35
|
-
describe enabled ? 'enabled' : 'disabled' do
|
|
36
|
-
before do
|
|
37
|
-
ParallelMinion::Minion.enabled = enabled
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'without parameters' do
|
|
41
|
-
minion = ParallelMinion::Minion.new { 196 }
|
|
42
|
-
assert_equal 196, minion.result
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it 'with a description' do
|
|
46
|
-
minion = ParallelMinion::Minion.new(description: 'Test') { 197 }
|
|
47
|
-
assert_equal 197, minion.result
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'with an argument' do
|
|
51
|
-
p1 = {name: 198}
|
|
52
|
-
minion = ParallelMinion::Minion.new(p1, description: 'Test') do |v|
|
|
53
|
-
v[:name]
|
|
54
|
-
end
|
|
55
|
-
assert_equal 198, minion.result
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'raise exception' do
|
|
59
|
-
minion = ParallelMinion::Minion.new(description: 'Test') { raise 'An exception' }
|
|
60
|
-
assert_raises RuntimeError do
|
|
61
|
-
minion.result
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'has correct logger name' do
|
|
66
|
-
minion = ParallelMinion::Minion.new { 196 }
|
|
67
|
-
name = enabled ? 'Minion' : 'Inline'
|
|
68
|
-
assert_equal name, minion.logger.name
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# TODO: Blocks still have access to their original scope if variables cannot be
|
|
72
|
-
# resolved first by the parameters, then by the values in Minion itself
|
|
73
|
-
# it 'not have access to local variables' do
|
|
74
|
-
# name = 'Jack'
|
|
75
|
-
# minion = ParallelMinion::Minion.new(description: 'Test') { puts name }
|
|
76
|
-
# assert_raises NameError do
|
|
77
|
-
# minion.result
|
|
78
|
-
# end
|
|
79
|
-
# end
|
|
80
|
-
|
|
81
|
-
it 'run minion' do
|
|
82
|
-
hash = {value: 23}
|
|
83
|
-
value = 47
|
|
84
|
-
minion = ParallelMinion::Minion.new(hash, description: 'Test') do |h|
|
|
85
|
-
value = 321
|
|
86
|
-
h[:value] = 123
|
|
87
|
-
456
|
|
88
|
-
end
|
|
89
|
-
assert_equal 456, minion.result
|
|
90
|
-
assert_equal 123, hash[:value]
|
|
91
|
-
assert_equal 321, value
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it 'copy across logging tags' do
|
|
95
|
-
minion = nil
|
|
96
|
-
SemanticLogger.tagged('TAG') do
|
|
97
|
-
assert_equal 'TAG', SemanticLogger.tags.last
|
|
98
|
-
minion = ParallelMinion::Minion.new(description: 'Tag Test') do
|
|
99
|
-
logger.info 'Tag Test'
|
|
100
|
-
logger.tags.last
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
assert_equal 'TAG', minion.result
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it 'copy across named tags' do
|
|
107
|
-
minion = nil
|
|
108
|
-
SemanticLogger.named_tagged(tag: 'TAG') do
|
|
109
|
-
assert_equal({tag: 'TAG'}, SemanticLogger.named_tags)
|
|
110
|
-
minion = ParallelMinion::Minion.new(description: 'Named Tags Test') do
|
|
111
|
-
logger.info 'Named Tags Test'
|
|
112
|
-
SemanticLogger.named_tags
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
assert_equal({tag: 'TAG'}, minion.result)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it 'copy across tags and named tags' do
|
|
119
|
-
minion = nil
|
|
120
|
-
SemanticLogger.tagged('TAG') do
|
|
121
|
-
SemanticLogger.named_tagged(tag: 'TAG') do
|
|
122
|
-
assert_equal({tag: 'TAG'}, SemanticLogger.named_tags)
|
|
123
|
-
assert_equal 'TAG', SemanticLogger.tags.last
|
|
124
|
-
minion = ParallelMinion::Minion.new(description: 'Tags Test') do
|
|
125
|
-
logger.info 'Tags Test'
|
|
126
|
-
[SemanticLogger.named_tags, SemanticLogger.tags.last]
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
assert_equal({tag: 'TAG'}, minion.result.first)
|
|
130
|
-
assert_equal 'TAG', minion.result.last
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
it 'include metric' do
|
|
136
|
-
metric_name = 'model/method'
|
|
137
|
-
hash = {value: 23}
|
|
138
|
-
value = 47
|
|
139
|
-
minion = ParallelMinion::Minion.new(hash, description: 'Test', metric: metric_name) do |h|
|
|
140
|
-
value = 321
|
|
141
|
-
h[:value] = 123
|
|
142
|
-
sleep 1
|
|
143
|
-
456
|
|
144
|
-
end
|
|
145
|
-
assert_equal 456, minion.result
|
|
146
|
-
assert_equal 123, hash[:value]
|
|
147
|
-
assert_equal 321, value
|
|
148
|
-
|
|
149
|
-
assert log_messages.shift, -> { log_messages.ai }
|
|
150
|
-
assert completed_log = log_messages.shift, -> { log_messages.ai }
|
|
151
|
-
# Completed log message
|
|
152
|
-
assert_equal metric_name, completed_log.metric, -> { completed_log.ai }
|
|
153
|
-
if enabled
|
|
154
|
-
# Wait log message
|
|
155
|
-
assert waited_log = log_messages.shift, -> { log_messages.ai }
|
|
156
|
-
assert_equal "#{metric_name}/wait", waited_log.metric, -> { waited_log.ai }
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
it ':on_exception_level' do
|
|
161
|
-
minion = ParallelMinion::Minion.new(
|
|
162
|
-
description: 'Test',
|
|
163
|
-
on_exception_level: :error
|
|
164
|
-
) do |_h|
|
|
165
|
-
raise 'Oh No'
|
|
166
|
-
end
|
|
167
|
-
# Wait for thread to complete
|
|
168
|
-
assert_raises RuntimeError do
|
|
169
|
-
minion.result
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
assert log_messages.shift, -> { log_messages.ai }
|
|
173
|
-
assert completed_log = log_messages.shift, -> { log_messages.ai }
|
|
174
|
-
|
|
175
|
-
assert_equal :error, completed_log.level
|
|
176
|
-
assert_equal 'Completed Test -- Exception: RuntimeError: Oh No', completed_log.message
|
|
177
|
-
refute completed_log.backtrace.empty?
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
it 'handle multiple minions concurrently' do
|
|
181
|
-
# Start 10 minions
|
|
182
|
-
minions = Array.new(10) do |i|
|
|
183
|
-
# Each Minion returns its index in the collection
|
|
184
|
-
ParallelMinion::Minion.new(i, description: "Minion:#{i}") { |counter| counter }
|
|
185
|
-
end
|
|
186
|
-
assert_equal 10, minions.count
|
|
187
|
-
# Fetch the result from each Minion
|
|
188
|
-
minions.each_with_index do |minion, index|
|
|
189
|
-
assert_equal index, minion.result
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it 'timeout' do
|
|
194
|
-
if enabled
|
|
195
|
-
minion = ParallelMinion::Minion.new(description: 'Test', timeout: 100) { sleep 1 }
|
|
196
|
-
assert_nil minion.result
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
it 'timeout and terminate thread with Exception' do
|
|
201
|
-
if enabled
|
|
202
|
-
minion = ParallelMinion::Minion.new(description: 'Test', timeout: 100, on_timeout: Timeout::Error) { sleep 1 }
|
|
203
|
-
assert_nil minion.result
|
|
204
|
-
# Give time for thread to terminate
|
|
205
|
-
sleep 0.1
|
|
206
|
-
assert_equal Timeout::Error, minion.exception.class
|
|
207
|
-
assert_equal false, minion.working?
|
|
208
|
-
assert_equal true, minion.completed?
|
|
209
|
-
assert_equal true, minion.failed?
|
|
210
|
-
assert_equal 0, minion.time_left
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
it 'make description instance variable available' do
|
|
215
|
-
minion = ParallelMinion::Minion.new(description: 'Test') do
|
|
216
|
-
description
|
|
217
|
-
end
|
|
218
|
-
assert_equal 'Test', minion.result
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
it 'make timeout instance variable available' do
|
|
222
|
-
minion = ParallelMinion::Minion.new(description: 'Test', timeout: 1000) do
|
|
223
|
-
timeout
|
|
224
|
-
end
|
|
225
|
-
assert_equal 1000, minion.result
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
it 'make enabled? method available' do
|
|
229
|
-
minion = ParallelMinion::Minion.new(description: 'Test') do
|
|
230
|
-
enabled?
|
|
231
|
-
end
|
|
232
|
-
assert_equal enabled, minion.result
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
it 'keep the original arguments' do
|
|
236
|
-
minion = ParallelMinion::Minion.new(1, 'data', 14.1, description: 'Test') do |num, _str, float|
|
|
237
|
-
num + float
|
|
238
|
-
end
|
|
239
|
-
assert_equal 15.1, minion.result
|
|
240
|
-
assert_equal [1, 'data', 14.1], minion.arguments
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
end
|
data/test/test_db.sqlite3
DELETED
|
Binary file
|
data/test/test_helper.rb
DELETED