fleiss 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/bin/fleiss +3 -0
- data/fleiss.gemspec +1 -1
- data/lib/fleiss/cli.rb +2 -7
- data/lib/fleiss/worker.rb +21 -15
- data/lib/fleiss.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b76bfb38938511dcf5053855e5a9091ad694c0b1c1fafba3e551b5757aaa1dfe
|
4
|
+
data.tar.gz: 9ff274eeba83d0e5ffc878c4934a4c03bbc91ede2bd2eb0f7e6c026fdd3dc1bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b145758e74ac991211a2677409fe31a185a094ee3304d54d2cf41937446c257dba225a01183591743486e3d91725e37ffbec747c01f3a144652693645e08d5f6
|
7
|
+
data.tar.gz: 55909e4fbf2652fe613767eca254d585ac89e07ff8d2e40c5b6e502e266a8fda6dd4f02b32c4dc1cf880cfc33f83e8433fed30e255978531bb2f3ef621bd2a83
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fleiss (0.
|
4
|
+
fleiss (0.2.0)
|
5
5
|
activejob (>= 5.0)
|
6
6
|
activerecord (>= 5.0)
|
7
7
|
concurrent-ruby
|
@@ -25,11 +25,11 @@ GEM
|
|
25
25
|
tzinfo (~> 1.1)
|
26
26
|
arel (9.0.0)
|
27
27
|
ast (2.4.0)
|
28
|
-
concurrent-ruby (1.1.
|
28
|
+
concurrent-ruby (1.1.4)
|
29
29
|
diff-lcs (1.3)
|
30
30
|
globalid (0.4.1)
|
31
31
|
activesupport (>= 4.2.0)
|
32
|
-
i18n (1.
|
32
|
+
i18n (1.3.0)
|
33
33
|
concurrent-ruby (~> 1.0)
|
34
34
|
jaro_winkler (1.5.1)
|
35
35
|
minitest (5.11.3)
|
@@ -83,4 +83,4 @@ DEPENDENCIES
|
|
83
83
|
sqlite3
|
84
84
|
|
85
85
|
BUNDLED WITH
|
86
|
-
1.
|
86
|
+
1.17.2
|
data/bin/fleiss
CHANGED
data/fleiss.gemspec
CHANGED
data/lib/fleiss/cli.rb
CHANGED
@@ -2,7 +2,6 @@ require 'singleton'
|
|
2
2
|
require 'optparse'
|
3
3
|
require 'yaml'
|
4
4
|
require 'erb'
|
5
|
-
require 'logger'
|
6
5
|
|
7
6
|
module Fleiss
|
8
7
|
class CLI
|
@@ -15,7 +14,6 @@ module Fleiss
|
|
15
14
|
require: [],
|
16
15
|
concurrency: 10,
|
17
16
|
wait_time: 1.0,
|
18
|
-
logfile: STDOUT,
|
19
17
|
}.freeze
|
20
18
|
|
21
19
|
attr_reader :opts
|
@@ -46,14 +44,11 @@ module Fleiss
|
|
46
44
|
opts[:require].each {|n| require n }
|
47
45
|
require 'fleiss/worker'
|
48
46
|
|
49
|
-
|
50
|
-
logdev.sync = true if logdev.respond_to?(:sync=)
|
51
|
-
|
47
|
+
ActiveJob::Base.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(opts[:logfile])) if opts[:logfile]
|
52
48
|
Fleiss::Worker.run \
|
53
49
|
queues: opts[:queues],
|
54
50
|
concurrency: opts[:concurrency],
|
55
|
-
wait_time: opts[:wait_time]
|
56
|
-
logger: Logger.new(logdev)
|
51
|
+
wait_time: opts[:wait_time]
|
57
52
|
end
|
58
53
|
|
59
54
|
def parser # rubocop:disable Metrics/MethodLength
|
data/lib/fleiss/worker.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'fleiss'
|
2
2
|
require 'concurrent/executor/fixed_thread_pool'
|
3
3
|
require 'concurrent/atomic/atomic_fixnum'
|
4
|
-
require 'logger'
|
5
4
|
require 'securerandom'
|
6
5
|
|
7
6
|
class Fleiss::Worker
|
8
|
-
attr_reader :queues, :uuid, :wait_time
|
7
|
+
attr_reader :queues, :uuid, :wait_time
|
9
8
|
|
10
9
|
# Shortcut for new(*args).run
|
11
10
|
def self.run(*args)
|
@@ -18,24 +17,22 @@ class Fleiss::Worker
|
|
18
17
|
# @option [Array<String>] :queues queues to watch. Default: ["default"]
|
19
18
|
# @option [Integer] :concurrency the number of concurrent pool. Default: 10
|
20
19
|
# @option [Numeric] :wait_time maximum time (in seconds) to wait for jobs when retrieving next batch. Default: 1s.
|
21
|
-
|
22
|
-
def initialize(queues: [Fleiss::DEFAULT_QUEUE], concurrency: 10, wait_time: 1, logger: nil)
|
20
|
+
def initialize(queues: [Fleiss::DEFAULT_QUEUE], concurrency: 10, wait_time: 1)
|
23
21
|
@uuid = SecureRandom.uuid
|
24
22
|
@queues = Array(queues)
|
25
23
|
@pool = Concurrent::FixedThreadPool.new(concurrency, fallback_policy: :discard)
|
26
24
|
@wait_time = wait_time
|
27
|
-
@logger = logger || Logger.new(nil)
|
28
25
|
end
|
29
26
|
|
30
27
|
# Run starts the worker
|
31
28
|
def run
|
32
|
-
|
29
|
+
log(:info) { "Worker #{uuid} starting - queues: #{queues.inspect}, concurrency: #{@pool.max_length}" }
|
33
30
|
loop do
|
34
31
|
run_cycle
|
35
32
|
sleep @wait_time
|
36
33
|
end
|
37
34
|
rescue SignalException => e
|
38
|
-
|
35
|
+
log(:info) { "Worker #{uuid} received #{e.message}. Shutting down..." }
|
39
36
|
ensure
|
40
37
|
@pool.shutdown
|
41
38
|
@pool.wait_for_termination
|
@@ -43,6 +40,15 @@ class Fleiss::Worker
|
|
43
40
|
|
44
41
|
private
|
45
42
|
|
43
|
+
def log(severity, &block)
|
44
|
+
logger = ActiveJob::Base.logger
|
45
|
+
if logger.respond_to?(:tagged)
|
46
|
+
logger.tagged('Fleiss') { logger.send(severity, &block) }
|
47
|
+
else
|
48
|
+
logger.send(severity, &block)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
46
52
|
def run_cycle
|
47
53
|
return if @pool.shuttingdown?
|
48
54
|
|
@@ -67,7 +73,7 @@ class Fleiss::Worker
|
|
67
73
|
owner = "#{uuid}/#{thread_id}"
|
68
74
|
return unless job.start(owner)
|
69
75
|
|
70
|
-
|
76
|
+
log(:info) { "Worker #{uuid} execute job ##{job.id} (by thread #{thread_id})" }
|
71
77
|
finished = false
|
72
78
|
begin
|
73
79
|
ActiveJob::Base.execute job.job_data
|
@@ -83,12 +89,12 @@ class Fleiss::Worker
|
|
83
89
|
end
|
84
90
|
|
85
91
|
def handle_exception(err, intro)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
log(:error) do
|
93
|
+
[
|
94
|
+
"Worker #{uuid} error on #{intro}:",
|
95
|
+
"#{err.class.name}: #{err.message}",
|
96
|
+
err.backtrace,
|
97
|
+
].compact.flatten.join("\n")
|
98
|
+
end
|
93
99
|
end
|
94
100
|
end
|
data/lib/fleiss.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'active_job'
|
2
|
+
require 'active_job/queue_adapters/fleiss_adapter'
|
3
|
+
require 'fleiss/backend'
|
4
|
+
|
1
5
|
module Fleiss
|
2
6
|
DEFAULT_QUEUE = 'default'.freeze
|
3
7
|
|
@@ -5,5 +9,3 @@ module Fleiss
|
|
5
9
|
self::Backend::ActiveRecord
|
6
10
|
end
|
7
11
|
end
|
8
|
-
|
9
|
-
require 'fleiss/backend'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fleiss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Black Square Media Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|