jober 0.3.37 → 0.3.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/jober +9 -1
- data/lib/jober.rb +2 -1
- data/lib/jober/abstract_task.rb +2 -1
- data/lib/jober/logger.rb +1 -0
- data/lib/jober/queue.rb +4 -0
- data/lib/jober/slow_queue.rb +12 -0
- data/lib/jober/threaded_manager.rb +4 -1
- data/lib/jober/version.rb +1 -1
- data/spec/slow_queue_spec.rb +42 -0
- data/spec/threaded_manager_spec.rb +6 -3
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00c159d15e3e82299c7bab18a5a9793925955a09
|
4
|
+
data.tar.gz: c59fe0b176b51fc601e04a647b73209fd0519e62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b70718209990268efaa926bf9044d1bccf52cc010b3d215f365607a0771dd2461025749a9cdb77797f5dd4ded4b1da59e33c3af7bc49fc3c7354fca9b7f06cf3
|
7
|
+
data.tar.gz: 99c68a86e99ec22e92b480abcd9d6e61a627ba31f13ff0f38a0591b59fbfb24f9fe62957d071ff4a7c0c77c4053439edd8fb69e0266fffe076f015ade2b59404
|
data/bin/jober
CHANGED
@@ -36,13 +36,21 @@ end.parse!
|
|
36
36
|
|
37
37
|
if req = options[:require]
|
38
38
|
require File.expand_path(req)
|
39
|
+
else
|
40
|
+
filenames = []
|
41
|
+
filenames << File.expand_path(ENV['APP_ROOT']) if ENV['APP_ROOT']
|
42
|
+
filenames << File.expand_path('config/environment')
|
43
|
+
filenames << File.expand_path('config/environment.rb')
|
44
|
+
filenames.each do |filename|
|
45
|
+
require filename if File.exist?(filename)
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
klass_name = options[:klass]
|
42
50
|
klass = Jober.find_class(klass_name)
|
43
51
|
|
44
52
|
unless klass
|
45
|
-
puts "
|
53
|
+
puts "Please set class_name by option -c"
|
46
54
|
exit(1)
|
47
55
|
end
|
48
56
|
|
data/lib/jober.rb
CHANGED
@@ -9,6 +9,7 @@ module Jober
|
|
9
9
|
autoload :AbstractTask, 'jober/abstract_task'
|
10
10
|
autoload :Task, 'jober/task'
|
11
11
|
autoload :Queue, 'jober/queue'
|
12
|
+
autoload :SlowQueue, 'jober/slow_queue'
|
12
13
|
autoload :QueueBatch, 'jober/queue_batch'
|
13
14
|
autoload :UniqueQueue, 'jober/unique_queue'
|
14
15
|
autoload :Logger, 'jober/logger'
|
@@ -40,7 +41,7 @@ module Jober
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def internal_classes_names
|
43
|
-
@internal_classes_names ||= (%w{Manager ThreadedManager AbstractTask Task Queue} +
|
44
|
+
@internal_classes_names ||= (%w{Manager ThreadedManager AbstractTask Task Queue SlowQueue} +
|
44
45
|
%w{QueueBatch UniqueQueue UniqueQueueBatch Logger SharedObject ARLoop Exception}).map { |k| "Jober::#{k}" }
|
45
46
|
end
|
46
47
|
|
data/lib/jober/abstract_task.rb
CHANGED
@@ -32,7 +32,7 @@ class Jober::AbstractTask
|
|
32
32
|
attr_accessor :short_name
|
33
33
|
end
|
34
34
|
|
35
|
-
attr_reader :finished, :stopped, :worker_id, :workers_count
|
35
|
+
attr_reader :finished, :stopped, :worker_id, :workers_count, :unique_id
|
36
36
|
|
37
37
|
def self.inherited(base)
|
38
38
|
Jober.add_class(base)
|
@@ -51,6 +51,7 @@ class Jober::AbstractTask
|
|
51
51
|
@worker_id = (opts[:worker_id] || 0).to_i
|
52
52
|
@workers_count = (opts[:workers_count] || 1).to_i
|
53
53
|
@skip_delay = opts[:skip_delay]
|
54
|
+
@unique_id = opts[:unique_id]
|
54
55
|
end
|
55
56
|
|
56
57
|
def before_execute
|
data/lib/jober/logger.rb
CHANGED
@@ -12,6 +12,7 @@ module Jober::Logger
|
|
12
12
|
def logger_tag
|
13
13
|
@logger_tag ||= begin
|
14
14
|
tag = '[' + self.class.to_s
|
15
|
+
tag += "(#{unique_id})" if respond_to?(:unique_id) && unique_id.to_i > 0
|
15
16
|
tag += " #{@worker_id}-#{@workers_count}" if @worker_id && @workers_count && @workers_count > 1
|
16
17
|
tag += ']'
|
17
18
|
tag
|
data/lib/jober/queue.rb
CHANGED
@@ -13,13 +13,16 @@ class Jober::ThreadedManager
|
|
13
13
|
def initialize(klasses = nil, opts = {})
|
14
14
|
@klasses = Array(klasses || Jober.auto_classes)
|
15
15
|
@stopped = false
|
16
|
+
h = Hash.new(0)
|
16
17
|
@objects = @klasses.map do |klass|
|
17
18
|
if klass.is_a?(String)
|
18
19
|
klass_str = klass
|
19
20
|
klass = Jober.find_class(klass_str)
|
20
21
|
raise "unknown class #{klass_str}" unless klass
|
21
22
|
end
|
22
|
-
klass.new(opts)
|
23
|
+
obj = klass.new(opts.merge(:unique_id => h[klass]))
|
24
|
+
h[klass] += 1
|
25
|
+
obj
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
data/lib/jober/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/spec_helper"
|
2
|
+
|
3
|
+
class MySlowQueue < Jober::SlowQueue
|
4
|
+
interval 0.5
|
5
|
+
def perform(x)
|
6
|
+
$slow_counter += x
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "SlowQueue" do
|
11
|
+
before { $slow_counter = 0 }
|
12
|
+
|
13
|
+
it "should set internals" do
|
14
|
+
w = MySlowQueue.new
|
15
|
+
w.queue_name.should == 'Jober::queue:my_slow'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should execute" do
|
19
|
+
MySlowQueue.enqueue(1)
|
20
|
+
MySlowQueue.enqueue(2)
|
21
|
+
MySlowQueue.enqueue(3)
|
22
|
+
MySlowQueue.new.execute
|
23
|
+
$slow_counter.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "run_loop" do
|
27
|
+
MySlowQueue.enqueue(1)
|
28
|
+
MySlowQueue.enqueue(2)
|
29
|
+
MySlowQueue.enqueue(3)
|
30
|
+
t = Thread.new do
|
31
|
+
MySlowQueue.new.run_loop
|
32
|
+
end
|
33
|
+
sleep 0.1
|
34
|
+
$slow_counter.should == 1
|
35
|
+
sleep 0.6
|
36
|
+
$slow_counter.should == 3
|
37
|
+
sleep 0.6
|
38
|
+
$slow_counter.should == 6
|
39
|
+
t.kill
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -3,6 +3,7 @@ require "#{File.dirname(__FILE__)}/spec_helper"
|
|
3
3
|
class T1 < Jober::Task
|
4
4
|
def perform
|
5
5
|
SO["t1"] += 1
|
6
|
+
SO["un"] += [unique_id]
|
6
7
|
end
|
7
8
|
end
|
8
9
|
|
@@ -57,6 +58,7 @@ describe Jober::ThreadedManager do
|
|
57
58
|
SO["t3"] = 0
|
58
59
|
SO["t41"] = 0
|
59
60
|
SO["t5"] = 0
|
61
|
+
SO["un"] = []
|
60
62
|
end
|
61
63
|
|
62
64
|
it "just work" do
|
@@ -64,9 +66,10 @@ describe Jober::ThreadedManager do
|
|
64
66
|
SO["t1"].should == 1
|
65
67
|
end
|
66
68
|
|
67
|
-
|
68
|
-
run_threaded_manager_for(0.
|
69
|
-
|
69
|
+
it "run multiple identical tasks" do
|
70
|
+
run_threaded_manager_for(0.5, [T1, T1, T1])
|
71
|
+
sleep 0.2
|
72
|
+
SO["un"].sort.should == [0, 1, 2]
|
70
73
|
end
|
71
74
|
|
72
75
|
it "run multiple tasks" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jober
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Konstantin Makarchev'"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/jober/queue.rb
|
126
126
|
- lib/jober/queue_batch.rb
|
127
127
|
- lib/jober/shared_object.rb
|
128
|
+
- lib/jober/slow_queue.rb
|
128
129
|
- lib/jober/task.rb
|
129
130
|
- lib/jober/threaded_manager.rb
|
130
131
|
- lib/jober/unique_queue.rb
|
@@ -141,6 +142,7 @@ files:
|
|
141
142
|
- spec/queue_parallel_spec.rb
|
142
143
|
- spec/queue_spec.rb
|
143
144
|
- spec/shared_object_spec.rb
|
145
|
+
- spec/slow_queue_spec.rb
|
144
146
|
- spec/spec_helper.rb
|
145
147
|
- spec/stats_spec.rb
|
146
148
|
- spec/task_loop_spec.rb
|
@@ -168,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
170
|
version: '0'
|
169
171
|
requirements: []
|
170
172
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.4.7
|
172
174
|
signing_key:
|
173
175
|
specification_version: 4
|
174
176
|
summary: Simple background jobs, queues.
|
@@ -184,6 +186,7 @@ test_files:
|
|
184
186
|
- spec/queue_parallel_spec.rb
|
185
187
|
- spec/queue_spec.rb
|
186
188
|
- spec/shared_object_spec.rb
|
189
|
+
- spec/slow_queue_spec.rb
|
187
190
|
- spec/spec_helper.rb
|
188
191
|
- spec/stats_spec.rb
|
189
192
|
- spec/task_loop_spec.rb
|