que 0.14.3 → 1.0.0.beta

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.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +108 -14
  4. data/LICENSE.txt +1 -1
  5. data/README.md +49 -45
  6. data/bin/command_line_interface.rb +239 -0
  7. data/bin/que +8 -82
  8. data/docs/README.md +2 -0
  9. data/docs/active_job.md +6 -0
  10. data/docs/advanced_setup.md +7 -64
  11. data/docs/command_line_interface.md +45 -0
  12. data/docs/error_handling.md +65 -18
  13. data/docs/inspecting_the_queue.md +30 -80
  14. data/docs/job_helper_methods.md +27 -0
  15. data/docs/logging.md +3 -22
  16. data/docs/managing_workers.md +6 -61
  17. data/docs/middleware.md +15 -0
  18. data/docs/migrating.md +4 -7
  19. data/docs/multiple_queues.md +8 -4
  20. data/docs/shutting_down_safely.md +1 -1
  21. data/docs/using_plain_connections.md +39 -15
  22. data/docs/using_sequel.md +5 -3
  23. data/docs/writing_reliable_jobs.md +15 -24
  24. data/lib/que.rb +98 -182
  25. data/lib/que/active_job/extensions.rb +97 -0
  26. data/lib/que/active_record/connection.rb +51 -0
  27. data/lib/que/active_record/model.rb +48 -0
  28. data/lib/que/connection.rb +179 -0
  29. data/lib/que/connection_pool.rb +78 -0
  30. data/lib/que/job.rb +107 -156
  31. data/lib/que/job_cache.rb +240 -0
  32. data/lib/que/job_methods.rb +168 -0
  33. data/lib/que/listener.rb +176 -0
  34. data/lib/que/locker.rb +466 -0
  35. data/lib/que/metajob.rb +47 -0
  36. data/lib/que/migrations.rb +24 -17
  37. data/lib/que/migrations/4/down.sql +48 -0
  38. data/lib/que/migrations/4/up.sql +265 -0
  39. data/lib/que/poller.rb +267 -0
  40. data/lib/que/rails/railtie.rb +14 -0
  41. data/lib/que/result_queue.rb +35 -0
  42. data/lib/que/sequel/model.rb +51 -0
  43. data/lib/que/utils/assertions.rb +62 -0
  44. data/lib/que/utils/constantization.rb +19 -0
  45. data/lib/que/utils/error_notification.rb +68 -0
  46. data/lib/que/utils/freeze.rb +20 -0
  47. data/lib/que/utils/introspection.rb +50 -0
  48. data/lib/que/utils/json_serialization.rb +21 -0
  49. data/lib/que/utils/logging.rb +78 -0
  50. data/lib/que/utils/middleware.rb +33 -0
  51. data/lib/que/utils/queue_management.rb +18 -0
  52. data/lib/que/utils/transactions.rb +34 -0
  53. data/lib/que/version.rb +1 -1
  54. data/lib/que/worker.rb +128 -167
  55. data/que.gemspec +13 -2
  56. metadata +37 -80
  57. data/.rspec +0 -2
  58. data/.travis.yml +0 -64
  59. data/Gemfile +0 -24
  60. data/docs/customizing_que.md +0 -200
  61. data/lib/generators/que/install_generator.rb +0 -24
  62. data/lib/generators/que/templates/add_que.rb +0 -13
  63. data/lib/que/adapters/active_record.rb +0 -40
  64. data/lib/que/adapters/base.rb +0 -133
  65. data/lib/que/adapters/connection_pool.rb +0 -16
  66. data/lib/que/adapters/pg.rb +0 -21
  67. data/lib/que/adapters/pond.rb +0 -16
  68. data/lib/que/adapters/sequel.rb +0 -20
  69. data/lib/que/railtie.rb +0 -16
  70. data/lib/que/rake_tasks.rb +0 -59
  71. data/lib/que/sql.rb +0 -170
  72. data/spec/adapters/active_record_spec.rb +0 -175
  73. data/spec/adapters/connection_pool_spec.rb +0 -22
  74. data/spec/adapters/pg_spec.rb +0 -41
  75. data/spec/adapters/pond_spec.rb +0 -22
  76. data/spec/adapters/sequel_spec.rb +0 -57
  77. data/spec/gemfiles/Gemfile.current +0 -19
  78. data/spec/gemfiles/Gemfile.old +0 -19
  79. data/spec/gemfiles/Gemfile.older +0 -19
  80. data/spec/gemfiles/Gemfile.oldest +0 -19
  81. data/spec/spec_helper.rb +0 -129
  82. data/spec/support/helpers.rb +0 -25
  83. data/spec/support/jobs.rb +0 -35
  84. data/spec/support/shared_examples/adapter.rb +0 -42
  85. data/spec/support/shared_examples/multi_threaded_adapter.rb +0 -46
  86. data/spec/unit/configuration_spec.rb +0 -31
  87. data/spec/unit/connection_spec.rb +0 -14
  88. data/spec/unit/customization_spec.rb +0 -251
  89. data/spec/unit/enqueue_spec.rb +0 -245
  90. data/spec/unit/helper_spec.rb +0 -12
  91. data/spec/unit/logging_spec.rb +0 -101
  92. data/spec/unit/migrations_spec.rb +0 -84
  93. data/spec/unit/pool_spec.rb +0 -365
  94. data/spec/unit/run_spec.rb +0 -14
  95. data/spec/unit/states_spec.rb +0 -50
  96. data/spec/unit/stats_spec.rb +0 -46
  97. data/spec/unit/transaction_spec.rb +0 -36
  98. data/spec/unit/work_spec.rb +0 -596
  99. data/spec/unit/worker_spec.rb +0 -167
  100. data/tasks/benchmark.rb +0 -3
  101. data/tasks/rspec.rb +0 -14
  102. data/tasks/safe_shutdown.rb +0 -67
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_examples "a multi-threaded Que adapter" do
4
- it_behaves_like "a Que adapter"
5
-
6
- it "should allow multiple threads to check out their own connections" do
7
- one = nil
8
- two = nil
9
-
10
- q1, q2 = Queue.new, Queue.new
11
-
12
- thread = Thread.new do
13
- Que.adapter.checkout do |conn|
14
- q1.push nil
15
- q2.pop
16
- one = conn.object_id
17
- end
18
- end
19
-
20
- Que.adapter.checkout do |conn|
21
- q1.pop
22
- q2.push nil
23
- two = conn.object_id
24
- end
25
-
26
- thread.join
27
- one.should_not == two
28
- end
29
-
30
- it "should allow multiple workers to complete jobs simultaneously" do
31
- BlockJob.enqueue
32
- worker_1 = Que::Worker.new
33
- $q1.pop
34
-
35
- Que::Job.enqueue
36
- DB[:que_jobs].count.should be 2
37
-
38
- worker_2 = Que::Worker.new
39
- sleep_until { worker_2.sleeping? }
40
- DB[:que_jobs].count.should be 1
41
-
42
- $q2.push nil
43
- sleep_until { worker_1.sleeping? }
44
- DB[:que_jobs].count.should be 0
45
- end
46
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Que do
6
- it ".use_prepared_statements should be the opposite of disable_prepared_statements" do
7
- original_verbose = $VERBOSE
8
- $VERBOSE = nil
9
-
10
- Que.use_prepared_statements.should == true
11
- Que.disable_prepared_statements.should == false
12
-
13
- Que.disable_prepared_statements = true
14
- Que.use_prepared_statements.should == false
15
- Que.disable_prepared_statements.should == true
16
-
17
- Que.disable_prepared_statements = nil
18
- Que.use_prepared_statements.should == true
19
- Que.disable_prepared_statements.should == false
20
-
21
- Que.use_prepared_statements = false
22
- Que.use_prepared_statements.should == false
23
- Que.disable_prepared_statements.should == true
24
-
25
- Que.use_prepared_statements = true
26
- Que.use_prepared_statements.should == true
27
- Que.disable_prepared_statements.should == false
28
-
29
- $VERBOSE = original_verbose
30
- end
31
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Que do
6
- it ".connection= with an unsupported connection should raise an error" do
7
- proc{Que.connection = "ferret"}.should raise_error RuntimeError, /Que connection not recognized: "ferret"/
8
- end
9
-
10
- it ".adapter when no connection has been established should raise an error" do
11
- Que.connection = nil
12
- proc{Que.adapter}.should raise_error RuntimeError, /Que connection not established!/
13
- end
14
- end
@@ -1,251 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- # A few specs to ensure that the ideas given in the customizing_que document
6
- # stay functional.
7
- describe "Customizing Que" do
8
- it "Cron should allow for easy recurring jobs" do
9
- begin
10
- class CronJob < Que::Job
11
- # Default repetition interval in seconds. Can be overridden in
12
- # subclasses. Can use 1.minute if using Rails.
13
- INTERVAL = 60
14
-
15
- attr_reader :start_at, :end_at, :run_again_at, :time_range
16
-
17
- def _run
18
- args = attrs[:args].first
19
- @start_at, @end_at = Time.at(args.delete('start_at')), Time.at(args.delete('end_at'))
20
- @run_again_at = @end_at + self.class::INTERVAL
21
- @time_range = @start_at...@end_at
22
-
23
- super
24
-
25
- args['start_at'] = @end_at.to_f
26
- args['end_at'] = @run_again_at.to_f
27
- self.class.enqueue(args, run_at: @run_again_at)
28
- end
29
- end
30
-
31
- class MyCronJob < CronJob
32
- INTERVAL = 1.5
33
-
34
- def run(args)
35
- $args = args.dup
36
- $time_range = time_range
37
- end
38
- end
39
-
40
- t = (Time.now - 1000).to_f.round(6)
41
- MyCronJob.enqueue :start_at => t, :end_at => t + 1.5, :arg => 4
42
-
43
- $args.should be nil
44
- $time_range.should be nil
45
-
46
- Que::Job.work
47
-
48
- $args.should == {'arg' => 4}
49
- $time_range.begin.to_f.round(6).should be_within(0.000001).of t
50
- $time_range.end.to_f.round(6).should be_within(0.000001).of t + 1.5
51
- $time_range.exclude_end?.should be true
52
-
53
- DB[:que_jobs].get(:run_at).to_f.round(6).should be_within(0.000001).of(t + 3.0)
54
- args = JSON.parse(DB[:que_jobs].get(:args)).first
55
- args.keys.should == ['arg', 'start_at', 'end_at']
56
- args['arg'].should == 4
57
- args['start_at'].should be_within(0.000001).of(t + 1.5)
58
- args['end_at'].should be_within(0.000001).of(t + 3.0)
59
- ensure
60
- $args = nil
61
- $time_range = nil
62
- end
63
- end
64
-
65
- it "Object#delay should allow for simpler job enqueueing" do
66
- begin
67
- class Delayed < Que::Job
68
- def run(receiver, method, args)
69
- Marshal.load(receiver).send method, *Marshal.load(args)
70
- end
71
- end
72
-
73
- class DelayedAction
74
- def initialize(receiver)
75
- @receiver = receiver
76
- end
77
-
78
- def method_missing(method, *args)
79
- Delayed.enqueue Marshal.dump(@receiver), method, Marshal.dump(args)
80
- end
81
- end
82
-
83
- class Object
84
- def delay
85
- DelayedAction.new(self)
86
- end
87
- end
88
-
89
- module MyModule
90
- class << self
91
- def blah
92
- $run = true
93
- end
94
- end
95
- end
96
-
97
- MyModule.delay.blah
98
- Que::Job.work
99
-
100
- $run.should be true
101
- ensure
102
- $run = nil
103
- end
104
- end
105
-
106
- it "QueueClassic-style jobs should be easy" do
107
- begin
108
- class Command < Que::Job
109
- def run(method, *args)
110
- receiver, message = method.split('.')
111
- Object.const_get(receiver).send(message, *args)
112
- end
113
- end
114
-
115
- module MyModule
116
- class << self
117
- def blah(arg)
118
- $value = arg
119
- end
120
- end
121
- end
122
-
123
- Command.enqueue "MyModule.blah", "hello world"
124
- Que::Job.work
125
-
126
- $value.should == "hello world"
127
- ensure
128
- $value = nil
129
- end
130
- end
131
-
132
- describe "retaining deleted jobs" do
133
- before do
134
- Que.execute "CREATE TABLE finished_jobs AS SELECT * FROM que_jobs LIMIT 0"
135
- end
136
-
137
- after do
138
- DB.drop_table? :finished_jobs
139
- end
140
-
141
- it "with a Ruby override" do
142
- class MyJobClass < Que::Job
143
- def destroy
144
- Que.execute "INSERT INTO finished_jobs SELECT * FROM que_jobs WHERE queue = $1::text AND priority = $2::integer AND run_at = $3::timestamptz AND job_id = $4::bigint", @attrs.values_at(:queue, :priority, :run_at, :job_id)
145
- super
146
- end
147
- end
148
-
149
- class MyJob < MyJobClass
150
- end
151
-
152
- MyJob.enqueue 1, 'arg1', :priority => 89
153
- Que::Job.work
154
-
155
- DB[:finished_jobs].count.should == 1
156
- job = DB[:finished_jobs].first
157
- job[:priority].should == 89
158
- JSON.load(job[:args]).should == [1, 'arg1']
159
- end
160
-
161
- it "with a trigger" do
162
- begin
163
- Que.execute <<-SQL
164
- CREATE FUNCTION please_save_my_job()
165
- RETURNS trigger
166
- LANGUAGE plpgsql
167
- AS $$
168
- BEGIN
169
- INSERT INTO finished_jobs SELECT (OLD).*;
170
- RETURN OLD;
171
- END;
172
- $$;
173
- SQL
174
-
175
- Que.execute "CREATE TRIGGER keep_all_my_old_jobs BEFORE DELETE ON que_jobs FOR EACH ROW EXECUTE PROCEDURE please_save_my_job();"
176
-
177
- Que::Job.enqueue 2, 'arg2', :priority => 45
178
- Que::Job.work
179
-
180
- DB[:finished_jobs].count.should == 1
181
- job = DB[:finished_jobs].first
182
- job[:priority].should == 45
183
- JSON.load(job[:args]).should == [2, 'arg2']
184
- ensure
185
- DB.drop_trigger :que_jobs, :keep_all_my_old_jobs, :if_exists => true
186
- DB.drop_function :please_save_my_job, :if_exists => true
187
- end
188
- end
189
- end
190
-
191
- describe "not retrying specific failed jobs" do
192
- before do
193
- Que.execute "CREATE TABLE failed_jobs AS SELECT * FROM que_jobs LIMIT 0"
194
- end
195
-
196
- after do
197
- DB.drop_table? :failed_jobs
198
- end
199
-
200
- it "should be easily achievable with a module" do
201
- begin
202
- module SkipRetries
203
- def run(*args)
204
- super
205
- rescue
206
- sql = <<-SQL
207
- WITH failed AS (
208
- DELETE
209
- FROM que_jobs
210
- WHERE queue = $1::text
211
- AND priority = $2::smallint
212
- AND run_at = $3::timestamptz
213
- AND job_id = $4::bigint
214
- RETURNING *
215
- )
216
- INSERT INTO failed_jobs
217
- SELECT * FROM failed;
218
- SQL
219
-
220
- Que.execute sql, @attrs.values_at(:queue, :priority, :run_at, :job_id)
221
-
222
- raise
223
- end
224
- end
225
-
226
- class SkipRetryJob < Que::Job
227
- prepend SkipRetries
228
-
229
- def run(*args)
230
- $retry_job_args = args
231
- raise "Fail!"
232
- end
233
- end
234
-
235
- SkipRetryJob.enqueue 1, 'arg1', :other_arg => 'blah'
236
- Que::Job.work
237
-
238
- $retry_job_args.should == [1, 'arg1', {'other_arg' => 'blah'}]
239
-
240
- DB[:que_jobs].count.should == 0
241
- DB[:failed_jobs].count.should == 1
242
-
243
- job = DB[:failed_jobs].first
244
- JSON.parse(job[:args]).should == [1, 'arg1', {'other_arg' => 'blah'}]
245
- job[:job_class].should == 'SkipRetryJob'
246
- ensure
247
- $retry_job_args = nil
248
- end
249
- end
250
- end
251
- end
@@ -1,245 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Que::Job, '.enqueue' do
6
- it "should be able to queue a job" do
7
- DB[:que_jobs].count.should be 0
8
- result = Que::Job.enqueue
9
- DB[:que_jobs].count.should be 1
10
-
11
- result.should be_an_instance_of Que::Job
12
- result.attrs[:queue].should == ''
13
- result.attrs[:priority].should == 100
14
- result.attrs[:args].should == []
15
-
16
- job = DB[:que_jobs].first
17
- job[:queue].should == ''
18
- job[:priority].should be 100
19
- job[:run_at].should be_within(3).of Time.now
20
- job[:job_class].should == "Que::Job"
21
- JSON.load(job[:args]).should == []
22
- end
23
-
24
- it "should be aliased to .queue" do
25
- DB[:que_jobs].count.should be 0
26
- suppress_warnings { Que::Job.queue }
27
- DB[:que_jobs].count.should be 1
28
- end
29
-
30
- it "should be able to queue a job with arguments" do
31
- DB[:que_jobs].count.should be 0
32
- Que::Job.enqueue 1, 'two'
33
- DB[:que_jobs].count.should be 1
34
-
35
- job = DB[:que_jobs].first
36
- job[:queue].should == ''
37
- job[:priority].should be 100
38
- job[:run_at].should be_within(3).of Time.now
39
- job[:job_class].should == "Que::Job"
40
- JSON.load(job[:args]).should == [1, 'two']
41
- end
42
-
43
- it "should be able to queue a job with complex arguments" do
44
- DB[:que_jobs].count.should be 0
45
- Que::Job.enqueue 1, 'two', :string => "string",
46
- :integer => 5,
47
- :array => [1, "two", {:three => 3}],
48
- :hash => {:one => 1, :two => 'two', :three => [3]}
49
-
50
- DB[:que_jobs].count.should be 1
51
-
52
- job = DB[:que_jobs].first
53
- job[:queue].should == ''
54
- job[:priority].should be 100
55
- job[:run_at].should be_within(3).of Time.now
56
- job[:job_class].should == "Que::Job"
57
- JSON.load(job[:args]).should == [
58
- 1,
59
- 'two',
60
- {
61
- 'string' => 'string',
62
- 'integer' => 5,
63
- 'array' => [1, "two", {"three" => 3}],
64
- 'hash' => {'one' => 1, 'two' => 'two', 'three' => [3]}
65
- }
66
- ]
67
- end
68
-
69
- it "should be able to queue a job with a specific time to run" do
70
- DB[:que_jobs].count.should be 0
71
- Que::Job.enqueue 1, :run_at => Time.now + 60
72
- DB[:que_jobs].count.should be 1
73
-
74
- job = DB[:que_jobs].first
75
- job[:queue].should == ''
76
- job[:priority].should be 100
77
- job[:run_at].should be_within(3).of Time.now + 60
78
- job[:job_class].should == "Que::Job"
79
- JSON.load(job[:args]).should == [1]
80
- end
81
-
82
- it "should be able to queue a job with a specific priority" do
83
- DB[:que_jobs].count.should be 0
84
- Que::Job.enqueue 1, :priority => 4
85
- DB[:que_jobs].count.should be 1
86
-
87
- job = DB[:que_jobs].first
88
- job[:queue].should == ''
89
- job[:priority].should be 4
90
- job[:run_at].should be_within(3).of Time.now
91
- job[:job_class].should == "Que::Job"
92
- JSON.load(job[:args]).should == [1]
93
- end
94
-
95
- it "should be able to queue a job with queueing options in addition to argument options" do
96
- DB[:que_jobs].count.should be 0
97
- Que::Job.enqueue 1, :string => "string", :run_at => Time.now + 60, :priority => 4
98
- DB[:que_jobs].count.should be 1
99
-
100
- job = DB[:que_jobs].first
101
- job[:queue].should == ''
102
- job[:priority].should be 4
103
- job[:run_at].should be_within(3).of Time.now + 60
104
- job[:job_class].should == "Que::Job"
105
- JSON.load(job[:args]).should == [1, {'string' => 'string'}]
106
- end
107
-
108
- it "should respect a job class defined as a string" do
109
- Que.enqueue 'argument', :queue => 'my_queue', :other_arg => 'other_arg', :job_class => 'MyJobClass'
110
- Que::Job.enqueue 'argument', :queue => 'my_queue', :other_arg => 'other_arg', :job_class => 'MyJobClass'
111
-
112
- DB[:que_jobs].count.should be 2
113
- DB[:que_jobs].all.each do |job|
114
- job[:job_class].should == 'MyJobClass'
115
- job[:queue].should == 'my_queue'
116
- JSON.load(job[:args]).should == ['argument', {'other_arg' => 'other_arg'}]
117
- end
118
- end
119
-
120
- it "should respect a default (but overridable) priority for the job class" do
121
- class DefaultPriorityJob < Que::Job
122
- @priority = 3
123
- end
124
-
125
- DB[:que_jobs].count.should be 0
126
- DefaultPriorityJob.enqueue 1
127
- DefaultPriorityJob.enqueue 1, :priority => 4
128
- DB[:que_jobs].count.should be 2
129
-
130
- first, second = DB[:que_jobs].order(:job_id).all
131
-
132
- first[:queue].should == ''
133
- first[:priority].should be 3
134
- first[:run_at].should be_within(3).of Time.now
135
- first[:job_class].should == "DefaultPriorityJob"
136
- JSON.load(first[:args]).should == [1]
137
-
138
- second[:queue].should == ''
139
- second[:priority].should be 4
140
- second[:run_at].should be_within(3).of Time.now
141
- second[:job_class].should == "DefaultPriorityJob"
142
- JSON.load(second[:args]).should == [1]
143
- end
144
-
145
- it "should respect the old @default_priority setting" do
146
- class OldDefaultPriorityJob < Que::Job
147
- @default_priority = 3
148
- end
149
-
150
- DB[:que_jobs].count.should be 0
151
- suppress_warnings do
152
- OldDefaultPriorityJob.enqueue 1
153
- OldDefaultPriorityJob.enqueue 1, :priority => 4
154
- end
155
- DB[:que_jobs].count.should be 2
156
-
157
- first, second = DB[:que_jobs].order(:job_id).all
158
-
159
- first[:queue].should == ''
160
- first[:priority].should be 3
161
- first[:run_at].should be_within(3).of Time.now
162
- first[:job_class].should == "OldDefaultPriorityJob"
163
- JSON.load(first[:args]).should == [1]
164
-
165
- second[:queue].should == ''
166
- second[:priority].should be 4
167
- second[:run_at].should be_within(3).of Time.now
168
- second[:job_class].should == "OldDefaultPriorityJob"
169
- JSON.load(second[:args]).should == [1]
170
- end
171
-
172
- it "should respect a default (but overridable) run_at for the job class" do
173
- class DefaultRunAtJob < Que::Job
174
- @run_at = -> { Time.now + 60 }
175
- end
176
-
177
- DB[:que_jobs].count.should be 0
178
- DefaultRunAtJob.enqueue 1
179
- DefaultRunAtJob.enqueue 1, :run_at => Time.now + 30
180
- DB[:que_jobs].count.should be 2
181
-
182
- first, second = DB[:que_jobs].order(:job_id).all
183
-
184
- first[:queue].should == ''
185
- first[:priority].should be 100
186
- first[:run_at].should be_within(3).of Time.now + 60
187
- first[:job_class].should == "DefaultRunAtJob"
188
- JSON.load(first[:args]).should == [1]
189
-
190
- second[:queue].should == ''
191
- second[:priority].should be 100
192
- second[:run_at].should be_within(3).of Time.now + 30
193
- second[:job_class].should == "DefaultRunAtJob"
194
- JSON.load(second[:args]).should == [1]
195
- end
196
-
197
- it "should respect the old @default_run_at setting" do
198
- class OldDefaultRunAtJob < Que::Job
199
- @default_run_at = -> { Time.now + 60 }
200
- end
201
-
202
- DB[:que_jobs].count.should be 0
203
- suppress_warnings do
204
- OldDefaultRunAtJob.enqueue 1
205
- OldDefaultRunAtJob.enqueue 1, :run_at => Time.now + 30
206
- end
207
- DB[:que_jobs].count.should be 2
208
-
209
- first, second = DB[:que_jobs].order(:job_id).all
210
-
211
- first[:queue].should == ''
212
- first[:priority].should be 100
213
- first[:run_at].should be_within(3).of Time.now + 60
214
- first[:job_class].should == "OldDefaultRunAtJob"
215
- JSON.load(first[:args]).should == [1]
216
-
217
- second[:queue].should == ''
218
- second[:priority].should be 100
219
- second[:run_at].should be_within(3).of Time.now + 30
220
- second[:job_class].should == "OldDefaultRunAtJob"
221
- JSON.load(second[:args]).should == [1]
222
- end
223
-
224
- it "should respect a default (but overridable) queue for the job class" do
225
- class NamedQueueJob < Que::Job
226
- @queue = :my_queue
227
- end
228
-
229
- DB[:que_jobs].count.should be 0
230
- NamedQueueJob.enqueue 1
231
- NamedQueueJob.enqueue 1, :queue => 'my_queue_2'
232
- NamedQueueJob.enqueue 1, :queue => :my_queue_2
233
- NamedQueueJob.enqueue 1, :queue => ''
234
- NamedQueueJob.enqueue 1, :queue => nil
235
- DB[:que_jobs].count.should be 5
236
-
237
- first, second, third, fourth, fifth = DB[:que_jobs].order(:job_id).select_map(:queue)
238
-
239
- first.should == 'my_queue'
240
- second.should == 'my_queue_2'
241
- third.should == 'my_queue_2'
242
- fourth.should == ''
243
- fifth.should == ''
244
- end
245
- end