que 0.14.3 → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/CHANGELOG.md +108 -14
- data/LICENSE.txt +1 -1
- data/README.md +49 -45
- data/bin/command_line_interface.rb +239 -0
- data/bin/que +8 -82
- data/docs/README.md +2 -0
- data/docs/active_job.md +6 -0
- data/docs/advanced_setup.md +7 -64
- data/docs/command_line_interface.md +45 -0
- data/docs/error_handling.md +65 -18
- data/docs/inspecting_the_queue.md +30 -80
- data/docs/job_helper_methods.md +27 -0
- data/docs/logging.md +3 -22
- data/docs/managing_workers.md +6 -61
- data/docs/middleware.md +15 -0
- data/docs/migrating.md +4 -7
- data/docs/multiple_queues.md +8 -4
- data/docs/shutting_down_safely.md +1 -1
- data/docs/using_plain_connections.md +39 -15
- data/docs/using_sequel.md +5 -3
- data/docs/writing_reliable_jobs.md +15 -24
- data/lib/que.rb +98 -182
- data/lib/que/active_job/extensions.rb +97 -0
- data/lib/que/active_record/connection.rb +51 -0
- data/lib/que/active_record/model.rb +48 -0
- data/lib/que/connection.rb +179 -0
- data/lib/que/connection_pool.rb +78 -0
- data/lib/que/job.rb +107 -156
- data/lib/que/job_cache.rb +240 -0
- data/lib/que/job_methods.rb +168 -0
- data/lib/que/listener.rb +176 -0
- data/lib/que/locker.rb +466 -0
- data/lib/que/metajob.rb +47 -0
- data/lib/que/migrations.rb +24 -17
- data/lib/que/migrations/4/down.sql +48 -0
- data/lib/que/migrations/4/up.sql +265 -0
- data/lib/que/poller.rb +267 -0
- data/lib/que/rails/railtie.rb +14 -0
- data/lib/que/result_queue.rb +35 -0
- data/lib/que/sequel/model.rb +51 -0
- data/lib/que/utils/assertions.rb +62 -0
- data/lib/que/utils/constantization.rb +19 -0
- data/lib/que/utils/error_notification.rb +68 -0
- data/lib/que/utils/freeze.rb +20 -0
- data/lib/que/utils/introspection.rb +50 -0
- data/lib/que/utils/json_serialization.rb +21 -0
- data/lib/que/utils/logging.rb +78 -0
- data/lib/que/utils/middleware.rb +33 -0
- data/lib/que/utils/queue_management.rb +18 -0
- data/lib/que/utils/transactions.rb +34 -0
- data/lib/que/version.rb +1 -1
- data/lib/que/worker.rb +128 -167
- data/que.gemspec +13 -2
- metadata +37 -80
- data/.rspec +0 -2
- data/.travis.yml +0 -64
- data/Gemfile +0 -24
- data/docs/customizing_que.md +0 -200
- data/lib/generators/que/install_generator.rb +0 -24
- data/lib/generators/que/templates/add_que.rb +0 -13
- data/lib/que/adapters/active_record.rb +0 -40
- data/lib/que/adapters/base.rb +0 -133
- data/lib/que/adapters/connection_pool.rb +0 -16
- data/lib/que/adapters/pg.rb +0 -21
- data/lib/que/adapters/pond.rb +0 -16
- data/lib/que/adapters/sequel.rb +0 -20
- data/lib/que/railtie.rb +0 -16
- data/lib/que/rake_tasks.rb +0 -59
- data/lib/que/sql.rb +0 -170
- data/spec/adapters/active_record_spec.rb +0 -175
- data/spec/adapters/connection_pool_spec.rb +0 -22
- data/spec/adapters/pg_spec.rb +0 -41
- data/spec/adapters/pond_spec.rb +0 -22
- data/spec/adapters/sequel_spec.rb +0 -57
- data/spec/gemfiles/Gemfile.current +0 -19
- data/spec/gemfiles/Gemfile.old +0 -19
- data/spec/gemfiles/Gemfile.older +0 -19
- data/spec/gemfiles/Gemfile.oldest +0 -19
- data/spec/spec_helper.rb +0 -129
- data/spec/support/helpers.rb +0 -25
- data/spec/support/jobs.rb +0 -35
- data/spec/support/shared_examples/adapter.rb +0 -42
- data/spec/support/shared_examples/multi_threaded_adapter.rb +0 -46
- data/spec/unit/configuration_spec.rb +0 -31
- data/spec/unit/connection_spec.rb +0 -14
- data/spec/unit/customization_spec.rb +0 -251
- data/spec/unit/enqueue_spec.rb +0 -245
- data/spec/unit/helper_spec.rb +0 -12
- data/spec/unit/logging_spec.rb +0 -101
- data/spec/unit/migrations_spec.rb +0 -84
- data/spec/unit/pool_spec.rb +0 -365
- data/spec/unit/run_spec.rb +0 -14
- data/spec/unit/states_spec.rb +0 -50
- data/spec/unit/stats_spec.rb +0 -46
- data/spec/unit/transaction_spec.rb +0 -36
- data/spec/unit/work_spec.rb +0 -596
- data/spec/unit/worker_spec.rb +0 -167
- data/tasks/benchmark.rb +0 -3
- data/tasks/rspec.rb +0 -14
- data/tasks/safe_shutdown.rb +0 -67
data/spec/unit/helper_spec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Que, 'helpers' do
|
6
|
-
it "should be able to clear the jobs table" do
|
7
|
-
DB[:que_jobs].insert :job_class => "Que::Job"
|
8
|
-
DB[:que_jobs].count.should be 1
|
9
|
-
Que.clear!
|
10
|
-
DB[:que_jobs].count.should be 0
|
11
|
-
end
|
12
|
-
end
|
data/spec/unit/logging_spec.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "Logging" do
|
6
|
-
it "by default should record the library and hostname and thread id in JSON" do
|
7
|
-
Que.log :event => "blah", :source => 4
|
8
|
-
$logger.messages.count.should be 1
|
9
|
-
|
10
|
-
message = JSON.load($logger.messages.first)
|
11
|
-
message['lib'].should == 'que'
|
12
|
-
message['hostname'].should == Socket.gethostname
|
13
|
-
message['pid'].should == Process.pid
|
14
|
-
message['event'].should == 'blah'
|
15
|
-
message['source'].should == 4
|
16
|
-
message['thread'].should == Thread.current.object_id
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should allow a callable to be set as the logger" do
|
20
|
-
begin
|
21
|
-
# Make sure we can get through a work cycle without a logger.
|
22
|
-
Que.logger = proc { $logger }
|
23
|
-
|
24
|
-
Que::Job.enqueue
|
25
|
-
worker = Que::Worker.new
|
26
|
-
sleep_until { worker.sleeping? }
|
27
|
-
|
28
|
-
DB[:que_jobs].should be_empty
|
29
|
-
|
30
|
-
worker.stop
|
31
|
-
worker.wait_until_stopped
|
32
|
-
|
33
|
-
$logger.messages.count.should be 2
|
34
|
-
$logger.messages.map{|m| JSON.load(m)['event']}.should == ['job_worked', 'job_unavailable']
|
35
|
-
ensure
|
36
|
-
Que.logger = $logger
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should not raise an error when no logger is present" do
|
41
|
-
begin
|
42
|
-
# Make sure we can get through a work cycle without a logger.
|
43
|
-
Que.logger = nil
|
44
|
-
|
45
|
-
Que::Job.enqueue
|
46
|
-
worker = Que::Worker.new
|
47
|
-
sleep_until { worker.sleeping? }
|
48
|
-
|
49
|
-
DB[:que_jobs].should be_empty
|
50
|
-
|
51
|
-
worker.stop
|
52
|
-
worker.wait_until_stopped
|
53
|
-
ensure
|
54
|
-
Que.logger = $logger
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should allow the use of a custom log formatter" do
|
59
|
-
begin
|
60
|
-
Que.log_formatter = proc { |data| "Logged event is #{data[:event]}" }
|
61
|
-
Que.log :event => 'my_event'
|
62
|
-
$logger.messages.count.should be 1
|
63
|
-
$logger.messages.first.should == "Logged event is my_event"
|
64
|
-
ensure
|
65
|
-
Que.log_formatter = nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should not log anything if the logging formatter returns falsey" do
|
70
|
-
begin
|
71
|
-
Que.log_formatter = proc { |data| false }
|
72
|
-
|
73
|
-
Que.log :event => "blah"
|
74
|
-
$logger.messages.should be_empty
|
75
|
-
ensure
|
76
|
-
Que.log_formatter = nil
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should use a :level option to set the log level if one exists, or default to info" do
|
81
|
-
begin
|
82
|
-
Que.logger = o = Object.new
|
83
|
-
|
84
|
-
def o.method_missing(level, message)
|
85
|
-
$level = level
|
86
|
-
$message = message
|
87
|
-
end
|
88
|
-
|
89
|
-
Que.log :message => 'one'
|
90
|
-
$level.should == :info
|
91
|
-
JSON.load($message)['message'].should == 'one'
|
92
|
-
|
93
|
-
Que.log :message => 'two', :level => 'debug'
|
94
|
-
$level.should == :debug
|
95
|
-
JSON.load($message)['message'].should == 'two'
|
96
|
-
ensure
|
97
|
-
Que.logger = $logger
|
98
|
-
$level = $message = nil
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Que::Migrations do
|
6
|
-
it "should be able to perform migrations up and down" do
|
7
|
-
# Migration #1 creates the table with a priority default of 1, migration
|
8
|
-
# #2 ups that to 100.
|
9
|
-
|
10
|
-
default = proc do
|
11
|
-
result = Que.execute <<-SQL
|
12
|
-
select adsrc::integer
|
13
|
-
from pg_attribute a
|
14
|
-
join pg_class c on c.oid = a.attrelid
|
15
|
-
join pg_attrdef on adrelid = attrelid AND adnum = attnum
|
16
|
-
where relname = 'que_jobs'
|
17
|
-
and attname = 'priority'
|
18
|
-
SQL
|
19
|
-
|
20
|
-
result.first[:adsrc]
|
21
|
-
end
|
22
|
-
|
23
|
-
default.call.should == 100
|
24
|
-
Que::Migrations.migrate! :version => 1
|
25
|
-
default.call.should == 1
|
26
|
-
Que::Migrations.migrate! :version => 2
|
27
|
-
default.call.should == 100
|
28
|
-
|
29
|
-
# Clean up.
|
30
|
-
Que.migrate!
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should be able to get and set the current schema version" do
|
34
|
-
Que::Migrations.db_version.should == Que::Migrations::CURRENT_VERSION
|
35
|
-
Que::Migrations.set_db_version(59328)
|
36
|
-
Que::Migrations.db_version.should == 59328
|
37
|
-
Que::Migrations.set_db_version(Que::Migrations::CURRENT_VERSION)
|
38
|
-
Que::Migrations.db_version.should == Que::Migrations::CURRENT_VERSION
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should be able to cycle the jobs table all the way between nonexistent and current without error" do
|
42
|
-
Que::Migrations.db_version.should == Que::Migrations::CURRENT_VERSION
|
43
|
-
Que::Migrations.migrate! :version => 0
|
44
|
-
Que::Migrations.db_version.should == 0
|
45
|
-
Que.db_version.should == 0
|
46
|
-
Que::Migrations.migrate!
|
47
|
-
Que::Migrations.db_version.should == Que::Migrations::CURRENT_VERSION
|
48
|
-
|
49
|
-
# The helper on the Que module does the same thing.
|
50
|
-
Que.migrate! :version => 0
|
51
|
-
Que::Migrations.db_version.should == 0
|
52
|
-
Que.migrate!
|
53
|
-
Que::Migrations.db_version.should == Que::Migrations::CURRENT_VERSION
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should be able to honor the initial behavior of Que.drop!" do
|
57
|
-
DB.table_exists?(:que_jobs).should be true
|
58
|
-
Que.drop!
|
59
|
-
DB.table_exists?(:que_jobs).should be false
|
60
|
-
|
61
|
-
# Clean up.
|
62
|
-
Que::Migrations.migrate!
|
63
|
-
DB.table_exists?(:que_jobs).should be true
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should be able to recognize a que_jobs table created before the versioning system" do
|
67
|
-
DB.drop_table :que_jobs
|
68
|
-
DB.create_table(:que_jobs){serial :id} # Dummy Table.
|
69
|
-
Que::Migrations.db_version.should == 1
|
70
|
-
DB.drop_table(:que_jobs)
|
71
|
-
Que::Migrations.migrate!
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should be able to honor the initial behavior of Que.create!" do
|
75
|
-
DB.drop_table :que_jobs
|
76
|
-
Que.create!
|
77
|
-
DB.table_exists?(:que_jobs).should be true
|
78
|
-
Que::Migrations.db_version.should == 1
|
79
|
-
|
80
|
-
# Clean up.
|
81
|
-
Que::Migrations.migrate!
|
82
|
-
DB.table_exists?(:que_jobs).should be true
|
83
|
-
end
|
84
|
-
end
|
data/spec/unit/pool_spec.rb
DELETED
@@ -1,365 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "Managing the Worker pool" do
|
6
|
-
it "should log mode changes" do
|
7
|
-
Que.mode = :sync
|
8
|
-
Que.mode = :off
|
9
|
-
Que.mode = :off
|
10
|
-
|
11
|
-
$logger.messages.count.should be 3
|
12
|
-
m1, m2, m3 = $logger.messages.map { |m| JSON.load(m) }
|
13
|
-
|
14
|
-
m1['event'].should == 'mode_change'
|
15
|
-
m1['value'].should == 'sync'
|
16
|
-
|
17
|
-
m2['event'].should == 'mode_change'
|
18
|
-
m2['value'].should == 'off'
|
19
|
-
|
20
|
-
m3['event'].should == 'mode_change'
|
21
|
-
m3['value'].should == 'off'
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "Que.mode=" do
|
25
|
-
describe ":off" do
|
26
|
-
it "with worker_count 0 should not instantiate workers or hit the db" do
|
27
|
-
Que.connection = nil
|
28
|
-
Que.worker_count = 0
|
29
|
-
Que.mode = :off
|
30
|
-
Que::Worker.workers.should == []
|
31
|
-
end
|
32
|
-
|
33
|
-
it "with worker_count > 0 should not instantiate workers or hit the db" do
|
34
|
-
Que.connection = nil
|
35
|
-
Que.mode = :off
|
36
|
-
Que.worker_count = 5
|
37
|
-
Que.mode = :off
|
38
|
-
Que::Worker.workers.should == []
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe ":sync" do
|
43
|
-
it "with worker_count 0 should not instantiate workers or hit the db" do
|
44
|
-
Que.connection = nil
|
45
|
-
Que.worker_count = 0
|
46
|
-
Que.mode = :sync
|
47
|
-
Que::Worker.workers.should == []
|
48
|
-
end
|
49
|
-
|
50
|
-
it "with worker_count > 0 should not instantiate workers or hit the db" do
|
51
|
-
Que.connection = nil
|
52
|
-
Que.mode = :sync
|
53
|
-
Que.worker_count = 5
|
54
|
-
Que.mode = :sync
|
55
|
-
Que::Worker.workers.should == []
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should make jobs run in the same thread as they are queued" do
|
59
|
-
Que.mode = :sync
|
60
|
-
|
61
|
-
ArgsJob.enqueue(5, :testing => "synchronous").should be_an_instance_of ArgsJob
|
62
|
-
$passed_args.should == [5, {:testing => "synchronous"}]
|
63
|
-
DB[:que_jobs].count.should be 0
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should work fine with enqueuing jobs without a DB connection" do
|
67
|
-
Que.connection = nil
|
68
|
-
Que.mode = :sync
|
69
|
-
|
70
|
-
ArgsJob.enqueue(5, :testing => "synchronous").should be_an_instance_of ArgsJob
|
71
|
-
$passed_args.should == [5, {:testing => "synchronous"}]
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should not affect jobs that are queued with specific run_ats" do
|
75
|
-
Que.mode = :sync
|
76
|
-
|
77
|
-
ArgsJob.enqueue(5, :testing => "synchronous", :run_at => Time.now + 60)
|
78
|
-
DB[:que_jobs].select_map(:job_class).should == ["ArgsJob"]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe ":async" do
|
83
|
-
it "with worker_count 0 should not instantiate workers or hit the db" do
|
84
|
-
Que.connection = nil
|
85
|
-
Que.worker_count = 0
|
86
|
-
Que.mode = :async
|
87
|
-
Que::Worker.workers.map{|w| [w.state, w.thread.status]}.should == []
|
88
|
-
end
|
89
|
-
|
90
|
-
it "with worker_count > 0 should instantiate workers and hit the db" do
|
91
|
-
Que::Job.enqueue
|
92
|
-
Que.worker_count = 5
|
93
|
-
Que.mode = :async
|
94
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
95
|
-
DB[:que_jobs].count.should == 0
|
96
|
-
Que::Worker.workers.map{|w| [w.state, w.thread.status]}.should == [[:sleeping, 'sleep']] * 5
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should wake a worker every Que.wake_interval seconds" do
|
100
|
-
Que.worker_count = 4
|
101
|
-
Que.mode = :async
|
102
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
103
|
-
Que.wake_interval = 0.01 # 10 ms
|
104
|
-
Que::Job.enqueue
|
105
|
-
sleep_until { DB[:que_jobs].count == 0 }
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should work jobs in the queue defined by the Que.queue_name config option" do
|
109
|
-
begin
|
110
|
-
Que::Job.enqueue 1
|
111
|
-
Que::Job.enqueue 2, :queue => 'my_queue'
|
112
|
-
|
113
|
-
Que.queue_name = 'my_queue'
|
114
|
-
|
115
|
-
Que.mode = :async
|
116
|
-
Que.worker_count = 2
|
117
|
-
|
118
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
119
|
-
DB[:que_jobs].count.should be 1
|
120
|
-
|
121
|
-
job = DB[:que_jobs].first
|
122
|
-
job[:queue].should == ''
|
123
|
-
job[:args].should == '[1]'
|
124
|
-
ensure
|
125
|
-
Que.queue_name = nil
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "Que.worker_count=" do
|
132
|
-
describe "when the mode is :off" do
|
133
|
-
it "should record the setting but not instantiate any workers" do
|
134
|
-
Que.worker_count.should == 0
|
135
|
-
Que.connection = nil
|
136
|
-
Que.mode = :off
|
137
|
-
Que::Worker.workers.should == []
|
138
|
-
|
139
|
-
Que.worker_count = 4
|
140
|
-
Que.worker_count.should == 4
|
141
|
-
Que::Worker.workers.should == []
|
142
|
-
|
143
|
-
Que.worker_count = 6
|
144
|
-
Que.worker_count.should == 6
|
145
|
-
Que::Worker.workers.should == []
|
146
|
-
|
147
|
-
Que.worker_count = 2
|
148
|
-
Que.worker_count.should == 2
|
149
|
-
Que::Worker.workers.should == []
|
150
|
-
|
151
|
-
Que.worker_count = 0
|
152
|
-
Que.worker_count.should == 0
|
153
|
-
Que::Worker.workers.should == []
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe "when the mode is :sync" do
|
158
|
-
it "should record the setting but not instantiate any workers" do
|
159
|
-
Que.worker_count.should == 0
|
160
|
-
Que.connection = nil
|
161
|
-
Que.mode = :sync
|
162
|
-
Que::Worker.workers.should == []
|
163
|
-
|
164
|
-
Que.worker_count = 4
|
165
|
-
Que.worker_count.should == 4
|
166
|
-
Que::Worker.workers.should == []
|
167
|
-
|
168
|
-
Que.worker_count = 6
|
169
|
-
Que.worker_count.should == 6
|
170
|
-
Que::Worker.workers.should == []
|
171
|
-
|
172
|
-
Que.worker_count = 2
|
173
|
-
Que.worker_count.should == 2
|
174
|
-
Que::Worker.workers.should == []
|
175
|
-
|
176
|
-
Que.worker_count = 0
|
177
|
-
Que.worker_count.should == 0
|
178
|
-
Que::Worker.workers.should == []
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "when the mode is :async" do
|
183
|
-
it "should start hitting the DB when transitioning to a non-zero value" do
|
184
|
-
Que.mode = :async
|
185
|
-
Que::Job.enqueue
|
186
|
-
Que.worker_count = 4
|
187
|
-
sleep_until { Que::Worker.workers.all?(&:sleeping?) }
|
188
|
-
Que::Worker.workers.map{|w| [w.state, w.thread.status]}.should == [[:sleeping, 'sleep']] * 4
|
189
|
-
DB[:que_jobs].count.should == 0
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should stop hitting the DB when transitioning to zero" do
|
193
|
-
Que.mode = :async
|
194
|
-
Que.worker_count = 4
|
195
|
-
sleep_until { Que::Worker.workers.all?(&:sleeping?) }
|
196
|
-
Que.connection = nil
|
197
|
-
Que.worker_count = 0
|
198
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
199
|
-
[['mode_change', 'async'], ['worker_count_change', '4']] + [['job_unavailable', nil]] * 4 + [['worker_count_change', '0']]
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should be able to scale down the number of workers gracefully" do
|
203
|
-
Que.mode = :async
|
204
|
-
Que.worker_count = 4
|
205
|
-
|
206
|
-
workers = Que::Worker.workers.dup
|
207
|
-
workers.count.should be 4
|
208
|
-
sleep_until { Que::Worker.workers.all?(&:sleeping?) }
|
209
|
-
|
210
|
-
Que.worker_count = 2
|
211
|
-
Que::Worker.workers.count.should be 2
|
212
|
-
sleep_until { Que::Worker.workers.all?(&:sleeping?) }
|
213
|
-
|
214
|
-
workers[0..1].should == Que::Worker.workers
|
215
|
-
workers[2..3].each do |worker|
|
216
|
-
worker.should be_an_instance_of Que::Worker
|
217
|
-
worker.thread.status.should == false
|
218
|
-
end
|
219
|
-
|
220
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
221
|
-
[['mode_change', 'async'], ['worker_count_change', '4']] + [['job_unavailable', nil]] * 4 + [['worker_count_change', '2']]
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should be able to scale up the number of workers gracefully" do
|
225
|
-
Que.mode = :async
|
226
|
-
Que.worker_count = 4
|
227
|
-
workers = Que::Worker.workers.dup
|
228
|
-
workers.count.should be 4
|
229
|
-
|
230
|
-
sleep_until { Que::Worker.workers.all?(&:sleeping?) }
|
231
|
-
Que.worker_count = 6
|
232
|
-
Que::Worker.workers.count.should be 6
|
233
|
-
sleep_until { Que::Worker.workers.all?(&:sleeping?) }
|
234
|
-
|
235
|
-
workers.should == Que::Worker.workers[0..3]
|
236
|
-
|
237
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
238
|
-
[['mode_change', 'async'], ['worker_count_change', '4']] + [['job_unavailable', nil]] * 4 + [['worker_count_change', '6']] + [['job_unavailable', nil]] * 2
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
describe "Que.wake!" do
|
244
|
-
it "when mode = :off should do nothing" do
|
245
|
-
Que.connection = nil
|
246
|
-
Que.mode = :off
|
247
|
-
Que.worker_count = 4
|
248
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
249
|
-
Que.wake!
|
250
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
251
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
252
|
-
[['mode_change', 'off'], ['worker_count_change', '4']]
|
253
|
-
end
|
254
|
-
|
255
|
-
it "when mode = :sync should do nothing" do
|
256
|
-
Que.connection = nil
|
257
|
-
Que.mode = :sync
|
258
|
-
Que.worker_count = 4
|
259
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
260
|
-
Que.wake!
|
261
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
262
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
263
|
-
[['mode_change', 'sync'], ['worker_count_change', '4']]
|
264
|
-
end
|
265
|
-
|
266
|
-
it "when mode = :async and worker_count = 0 should do nothing" do
|
267
|
-
Que.connection = nil
|
268
|
-
Que.mode = :async
|
269
|
-
Que.worker_count = 0
|
270
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
271
|
-
Que.wake!
|
272
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
273
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
274
|
-
[['mode_change', 'async'], ['worker_count_change', '0']]
|
275
|
-
end
|
276
|
-
|
277
|
-
it "when mode = :async and worker_count > 0 should wake up a single worker" do
|
278
|
-
Que.mode = :async
|
279
|
-
Que.worker_count = 4
|
280
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
281
|
-
|
282
|
-
BlockJob.enqueue
|
283
|
-
Que.wake!
|
284
|
-
|
285
|
-
$q1.pop
|
286
|
-
Que::Worker.workers.first.should be_working
|
287
|
-
Que::Worker.workers[1..3].each { |w| w.should be_sleeping }
|
288
|
-
DB[:que_jobs].count.should be 1
|
289
|
-
$q2.push nil
|
290
|
-
|
291
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
292
|
-
DB[:que_jobs].count.should be 0
|
293
|
-
end
|
294
|
-
|
295
|
-
it "when mode = :async and worker_count > 0 should be thread-safe" do
|
296
|
-
Que.mode = :async
|
297
|
-
Que.worker_count = 4
|
298
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
299
|
-
threads = 4.times.map { Thread.new { 100.times { Que.wake! } } }
|
300
|
-
threads.each(&:join)
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
describe "Que.wake_all!" do
|
305
|
-
it "when mode = :off should do nothing" do
|
306
|
-
Que.connection = nil
|
307
|
-
Que.mode = :off
|
308
|
-
Que.worker_count = 4
|
309
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
310
|
-
Que.wake_all!
|
311
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
312
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
313
|
-
[['mode_change', 'off'], ['worker_count_change', '4']]
|
314
|
-
end
|
315
|
-
|
316
|
-
it "when mode = :sync should do nothing" do
|
317
|
-
Que.connection = nil
|
318
|
-
Que.mode = :sync
|
319
|
-
Que.worker_count = 4
|
320
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
321
|
-
Que.wake_all!
|
322
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
323
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
324
|
-
[['mode_change', 'sync'], ['worker_count_change', '4']]
|
325
|
-
end
|
326
|
-
|
327
|
-
it "when mode = :async and worker_count = 0 should do nothing" do
|
328
|
-
Que.connection = nil
|
329
|
-
Que.mode = :async
|
330
|
-
Que.worker_count = 0
|
331
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
332
|
-
Que.wake_all!
|
333
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
334
|
-
$logger.messages.map{|m| JSON.load(m).values_at('event', 'value')}.should ==
|
335
|
-
[['mode_change', 'async'], ['worker_count_change', '0']]
|
336
|
-
end
|
337
|
-
|
338
|
-
# This spec requires at least four connections.
|
339
|
-
it "when mode = :async and worker_count > 0 should wake up all workers" do
|
340
|
-
Que.adapter = QUE_ADAPTERS[:pond]
|
341
|
-
|
342
|
-
Que.mode = :async
|
343
|
-
Que.worker_count = 4
|
344
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
345
|
-
|
346
|
-
4.times { BlockJob.enqueue }
|
347
|
-
Que.wake_all!
|
348
|
-
4.times { $q1.pop }
|
349
|
-
|
350
|
-
Que::Worker.workers.each{ |worker| worker.should be_working }
|
351
|
-
4.times { $q2.push nil }
|
352
|
-
|
353
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
354
|
-
DB[:que_jobs].count.should be 0
|
355
|
-
end if QUE_ADAPTERS[:pond]
|
356
|
-
|
357
|
-
it "when mode = :async and worker_count > 0 should be thread-safe" do
|
358
|
-
Que.mode = :async
|
359
|
-
Que.worker_count = 4
|
360
|
-
sleep_until { Que::Worker.workers.all? &:sleeping? }
|
361
|
-
threads = 4.times.map { Thread.new { 100.times { Que.wake_all! } } }
|
362
|
-
threads.each(&:join)
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|