que 1.0.0.beta3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +43 -0
- data/CHANGELOG.md +250 -6
- data/Dockerfile +20 -0
- data/README.md +125 -27
- data/auto/dev +21 -0
- data/auto/psql +9 -0
- data/auto/test +5 -0
- data/auto/test-postgres-14 +17 -0
- data/bin/command_line_interface.rb +2 -2
- data/docker-compose.yml +46 -0
- data/docs/README.md +785 -33
- data/lib/que/active_record/connection.rb +1 -1
- data/lib/que/active_record/model.rb +1 -1
- data/lib/que/connection.rb +11 -1
- data/lib/que/job_buffer.rb +27 -22
- data/lib/que/locker.rb +9 -4
- data/lib/que/sequel/model.rb +14 -16
- data/lib/que/version.rb +1 -1
- data/lib/que/worker.rb +12 -4
- data/que.gemspec +2 -2
- data/scripts/docker-entrypoint +14 -0
- data/scripts/test +5 -0
- metadata +22 -30
- data/CHANGELOG.1.0.beta.md +0 -137
- data/docs/active_job.md +0 -6
- data/docs/advanced_setup.md +0 -49
- data/docs/command_line_interface.md +0 -49
- data/docs/error_handling.md +0 -94
- data/docs/inspecting_the_queue.md +0 -64
- data/docs/job_helper_methods.md +0 -27
- data/docs/logging.md +0 -62
- data/docs/managing_workers.md +0 -25
- data/docs/middleware.md +0 -36
- data/docs/migrating.md +0 -27
- data/docs/multiple_queues.md +0 -31
- data/docs/shutting_down_safely.md +0 -7
- data/docs/using_plain_connections.md +0 -65
- data/docs/using_sequel.md +0 -49
- data/docs/writing_reliable_jobs.md +0 -108
@@ -17,7 +17,7 @@ module Que
|
|
17
17
|
|
18
18
|
# Use Rails' executor (if present) to make sure that the connection
|
19
19
|
# we're using isn't taken from us while the block runs. See
|
20
|
-
# https://github.com/
|
20
|
+
# https://github.com/que-rb/que/issues/166#issuecomment-274218910
|
21
21
|
def wrap_in_rails_executor(&block)
|
22
22
|
if defined?(::Rails.application.executor)
|
23
23
|
::Rails.application.executor.wrap(&block)
|
data/lib/que/connection.rb
CHANGED
@@ -119,6 +119,10 @@ module Que
|
|
119
119
|
loop { break if next_notification.nil? }
|
120
120
|
end
|
121
121
|
|
122
|
+
def server_version
|
123
|
+
wrapped_connection.server_version
|
124
|
+
end
|
125
|
+
|
122
126
|
def in_transaction?
|
123
127
|
wrapped_connection.transaction_status != ::PG::PQTRANS_IDLE
|
124
128
|
end
|
@@ -152,7 +156,13 @@ module Que
|
|
152
156
|
},
|
153
157
|
|
154
158
|
# Timestamp with time zone
|
155
|
-
1184 =>
|
159
|
+
1184 => -> (value) {
|
160
|
+
case value
|
161
|
+
when Time then value
|
162
|
+
when String then Time.parse(value)
|
163
|
+
else raise "Unexpected time class: #{value.class} (#{value.inspect})"
|
164
|
+
end
|
165
|
+
}
|
156
166
|
}
|
157
167
|
|
158
168
|
# JSON, JSONB
|
data/lib/que/job_buffer.rb
CHANGED
@@ -59,10 +59,8 @@ module Que
|
|
59
59
|
|
60
60
|
# Relying on the hash's contents being sorted, here.
|
61
61
|
priority_queues.reverse_each do |_, pq|
|
62
|
-
pq.
|
63
|
-
|
64
|
-
break if job.nil? # False would mean we're stopping.
|
65
|
-
pq.push(job)
|
62
|
+
pq.populate do
|
63
|
+
_shift_job(pq.priority)
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
@@ -75,7 +73,7 @@ module Que
|
|
75
73
|
|
76
74
|
def shift(priority = nil)
|
77
75
|
queue = priority_queues.fetch(priority) { raise Error, "not a permitted priority! #{priority}" }
|
78
|
-
queue.pop
|
76
|
+
queue.pop || shift_job(priority)
|
79
77
|
end
|
80
78
|
|
81
79
|
def shift_job(priority = nil)
|
@@ -107,10 +105,6 @@ module Que
|
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
110
|
-
def jobs_needed?
|
111
|
-
minimum_size > size
|
112
|
-
end
|
113
|
-
|
114
108
|
def waiting_count
|
115
109
|
count = 0
|
116
110
|
priority_queues.each_value do |pq|
|
@@ -162,6 +156,10 @@ module Que
|
|
162
156
|
sync { _stopping? }
|
163
157
|
end
|
164
158
|
|
159
|
+
def job_available?(priority)
|
160
|
+
(job = @array.first) && job.priority_sufficient?(priority)
|
161
|
+
end
|
162
|
+
|
165
163
|
private
|
166
164
|
|
167
165
|
def _buffer_space
|
@@ -214,15 +212,14 @@ module Que
|
|
214
212
|
def pop
|
215
213
|
sync do
|
216
214
|
loop do
|
217
|
-
|
218
|
-
|
219
|
-
|
215
|
+
if @stopping
|
216
|
+
return false
|
217
|
+
elsif item = @items.pop
|
220
218
|
return item
|
219
|
+
elsif job_buffer.job_available?(priority)
|
220
|
+
return false
|
221
221
|
end
|
222
222
|
|
223
|
-
job = job_buffer.shift_job(priority)
|
224
|
-
return job unless job.nil? # False means we're stopping.
|
225
|
-
|
226
223
|
@waiting += 1
|
227
224
|
@cv.wait(mutex)
|
228
225
|
@waiting -= 1
|
@@ -230,18 +227,20 @@ module Que
|
|
230
227
|
end
|
231
228
|
end
|
232
229
|
|
233
|
-
def
|
230
|
+
def stop
|
234
231
|
sync do
|
235
|
-
|
236
|
-
@
|
237
|
-
@cv.signal
|
232
|
+
@stopping = true
|
233
|
+
@cv.broadcast
|
238
234
|
end
|
239
235
|
end
|
240
236
|
|
241
|
-
def
|
237
|
+
def populate
|
242
238
|
sync do
|
243
|
-
|
244
|
-
|
239
|
+
waiting_count.times do
|
240
|
+
job = yield
|
241
|
+
break if job.nil? # False would mean we're stopping.
|
242
|
+
_push(job)
|
243
|
+
end
|
245
244
|
end
|
246
245
|
end
|
247
246
|
|
@@ -254,6 +253,12 @@ module Que
|
|
254
253
|
def sync(&block)
|
255
254
|
mutex.synchronize(&block)
|
256
255
|
end
|
256
|
+
|
257
|
+
def _push(item)
|
258
|
+
Que.assert(waiting_count > 0)
|
259
|
+
@items << item
|
260
|
+
@cv.signal
|
261
|
+
end
|
257
262
|
end
|
258
263
|
end
|
259
264
|
end
|
data/lib/que/locker.rb
CHANGED
@@ -301,12 +301,15 @@ module Que
|
|
301
301
|
|
302
302
|
def poll
|
303
303
|
# Only poll when there are pollers to use (that is, when polling is
|
304
|
-
# enabled)
|
305
|
-
|
306
|
-
return unless pollers && job_buffer.jobs_needed?
|
304
|
+
# enabled).
|
305
|
+
return unless pollers
|
307
306
|
|
308
307
|
# Figure out what job priorities we have to fill.
|
309
308
|
priorities = job_buffer.available_priorities
|
309
|
+
|
310
|
+
# Only poll when there are workers ready for jobs.
|
311
|
+
return if priorities.empty?
|
312
|
+
|
310
313
|
all_metajobs = []
|
311
314
|
|
312
315
|
pollers.each do |poller|
|
@@ -390,10 +393,12 @@ module Que
|
|
390
393
|
}
|
391
394
|
end
|
392
395
|
|
396
|
+
materalize_cte = connection.server_version >= 12_00_00
|
397
|
+
|
393
398
|
jobs =
|
394
399
|
connection.execute \
|
395
400
|
<<-SQL
|
396
|
-
WITH jobs AS (SELECT * FROM que_jobs WHERE id IN (#{ids.join(', ')}))
|
401
|
+
WITH jobs AS #{materalize_cte ? 'MATERIALIZED' : ''} (SELECT * FROM que_jobs WHERE id IN (#{ids.join(', ')}))
|
397
402
|
SELECT * FROM jobs WHERE pg_try_advisory_lock(id)
|
398
403
|
SQL
|
399
404
|
|
data/lib/que/sequel/model.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
::Sequel.extension :pg_json_ops
|
4
|
+
|
3
5
|
module Que
|
4
6
|
module Sequel
|
5
7
|
QUALIFIED_TABLE = ::Sequel.qualify(:public, :que_jobs)
|
@@ -7,10 +9,10 @@ module Que
|
|
7
9
|
class Model < ::Sequel::Model(QUALIFIED_TABLE)
|
8
10
|
dataset_module do
|
9
11
|
conditions = {
|
10
|
-
errored:
|
11
|
-
expired:
|
12
|
-
finished:
|
13
|
-
scheduled:
|
12
|
+
errored: QUALIFIED_TABLE[:error_count] > 0,
|
13
|
+
expired: QUALIFIED_TABLE[:expired_at] !~ nil,
|
14
|
+
finished: QUALIFIED_TABLE[:finished_at] !~ nil,
|
15
|
+
scheduled: QUALIFIED_TABLE[:run_at] > ::Sequel::CURRENT_TIMESTAMP,
|
14
16
|
}
|
15
17
|
|
16
18
|
conditions.each do |name, condition|
|
@@ -18,32 +20,28 @@ module Que
|
|
18
20
|
subset :"not_#{name}", ~condition
|
19
21
|
end
|
20
22
|
|
21
|
-
subset :ready, conditions.values.map(&:~).inject
|
22
|
-
subset :not_ready, conditions.values. inject
|
23
|
+
subset :ready, conditions.values.map(&:~).inject(:&)
|
24
|
+
subset :not_ready, conditions.values. inject(:|)
|
23
25
|
|
24
26
|
def by_job_class(job_class)
|
25
27
|
job_class = job_class.name if job_class.is_a?(Class)
|
26
28
|
where(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
::Sequel.qualify(QUALIFIED_TABLE, :job_class) => "ActiveJob::QueueAdapters::QueAdapter::JobWrapper",
|
31
|
-
::Sequel.lit("public.que_jobs.args->0->>'job_class'") => job_class,
|
32
|
-
}
|
33
|
-
)
|
29
|
+
(QUALIFIED_TABLE[:job_class] =~ job_class) |
|
30
|
+
(QUALIFIED_TABLE[:job_class] =~ "ActiveJob::QueueAdapters::QueAdapter::JobWrapper") &
|
31
|
+
(QUALIFIED_TABLE[:args].pg_jsonb[0].get_text("job_class") =~ job_class)
|
34
32
|
)
|
35
33
|
end
|
36
34
|
|
37
35
|
def by_queue(queue)
|
38
|
-
where(
|
36
|
+
where(QUALIFIED_TABLE[:queue] => queue)
|
39
37
|
end
|
40
38
|
|
41
39
|
def by_tag(tag)
|
42
|
-
where(
|
40
|
+
where(QUALIFIED_TABLE[:data].pg_jsonb.contains(JSON.dump(tags: [tag])))
|
43
41
|
end
|
44
42
|
|
45
43
|
def by_args(*args)
|
46
|
-
where(
|
44
|
+
where(QUALIFIED_TABLE[:args].pg_jsonb.contains(JSON.dump(args)))
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
data/lib/que/version.rb
CHANGED
data/lib/que/worker.rb
CHANGED
@@ -54,10 +54,17 @@ module Que
|
|
54
54
|
private
|
55
55
|
|
56
56
|
def work_loop
|
57
|
-
# Blocks until a job of the appropriate priority is available.
|
58
|
-
#
|
57
|
+
# Blocks until a job of the appropriate priority is available.
|
58
|
+
# `fetch_next_metajob` normally returns a job to be processed.
|
59
|
+
# If the queue is shutting down it will return false, which breaks the loop and
|
59
60
|
# lets the thread finish.
|
60
|
-
while metajob = fetch_next_metajob
|
61
|
+
while (metajob = fetch_next_metajob) != false
|
62
|
+
# If metajob is nil instead of false, we've hit a rare race condition where
|
63
|
+
# there was a job in the buffer when the worker code checked, but the job was
|
64
|
+
# picked up by the time we got around to shifting it off the buffer.
|
65
|
+
# Letting this case go unhandled leads to worker threads exiting pre-maturely, so
|
66
|
+
# we check explicitly and continue the loop.
|
67
|
+
next if metajob.nil?
|
61
68
|
id = metajob.id
|
62
69
|
|
63
70
|
Que.internal_log(:worker_received_job, self) { {id: id} }
|
@@ -130,6 +137,7 @@ module Que
|
|
130
137
|
error: {
|
131
138
|
class: error.class.to_s,
|
132
139
|
message: error.message,
|
140
|
+
backtrace: (error.backtrace || []).join("\n").slice(0, 10000),
|
133
141
|
},
|
134
142
|
)
|
135
143
|
|
@@ -157,7 +165,7 @@ module Que
|
|
157
165
|
Que.execute :set_error, [
|
158
166
|
delay,
|
159
167
|
"#{error.class}: #{error.message}".slice(0, 500),
|
160
|
-
error.backtrace.join("\n").slice(0, 10000),
|
168
|
+
(error.backtrace || []).join("\n").slice(0, 10000),
|
161
169
|
job.fetch(:id),
|
162
170
|
]
|
163
171
|
end
|
data/que.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['christopher.m.hanks@gmail.com']
|
11
11
|
spec.description = %q{A job queue that uses PostgreSQL's advisory locks for speed and reliability.}
|
12
12
|
spec.summary = %q{A PostgreSQL-based Job Queue}
|
13
|
-
spec.homepage = 'https://github.com/
|
13
|
+
spec.homepage = 'https://github.com/que-rb/que'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
files_to_exclude = [
|
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
30
30
|
spec.require_paths = ['lib']
|
31
31
|
|
32
|
-
spec.add_development_dependency 'bundler'
|
32
|
+
spec.add_development_dependency 'bundler'
|
33
33
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -Eeuo pipefail
|
4
|
+
|
5
|
+
# For using your own dotfiles within the Docker container
|
6
|
+
if [ -f /.docker-rc.d/.docker-bashrc ]; then
|
7
|
+
echo "source /.docker-rc.d/.docker-bashrc" >> ~/.bashrc
|
8
|
+
fi
|
9
|
+
|
10
|
+
gem list -i -e bundler -v "$RUBY_BUNDLER_VERSION" >/dev/null || gem install bundler -v "$RUBY_BUNDLER_VERSION"
|
11
|
+
|
12
|
+
bundle check --dry-run || bundle install
|
13
|
+
|
14
|
+
exec "${@-bash}"
|
data/scripts/test
ADDED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: que
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hanks
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
description: A job queue that uses PostgreSQL's advisory locks for speed and reliability.
|
28
28
|
email:
|
29
29
|
- christopher.m.hanks@gmail.com
|
@@ -32,30 +32,21 @@ executables:
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
+
- ".github/workflows/tests.yml"
|
35
36
|
- ".gitignore"
|
36
|
-
- CHANGELOG.1.0.beta.md
|
37
37
|
- CHANGELOG.md
|
38
|
+
- Dockerfile
|
38
39
|
- LICENSE.txt
|
39
40
|
- README.md
|
40
41
|
- Rakefile
|
42
|
+
- auto/dev
|
43
|
+
- auto/psql
|
44
|
+
- auto/test
|
45
|
+
- auto/test-postgres-14
|
41
46
|
- bin/command_line_interface.rb
|
42
47
|
- bin/que
|
48
|
+
- docker-compose.yml
|
43
49
|
- docs/README.md
|
44
|
-
- docs/active_job.md
|
45
|
-
- docs/advanced_setup.md
|
46
|
-
- docs/command_line_interface.md
|
47
|
-
- docs/error_handling.md
|
48
|
-
- docs/inspecting_the_queue.md
|
49
|
-
- docs/job_helper_methods.md
|
50
|
-
- docs/logging.md
|
51
|
-
- docs/managing_workers.md
|
52
|
-
- docs/middleware.md
|
53
|
-
- docs/migrating.md
|
54
|
-
- docs/multiple_queues.md
|
55
|
-
- docs/shutting_down_safely.md
|
56
|
-
- docs/using_plain_connections.md
|
57
|
-
- docs/using_sequel.md
|
58
|
-
- docs/writing_reliable_jobs.md
|
59
50
|
- lib/que.rb
|
60
51
|
- lib/que/active_job/extensions.rb
|
61
52
|
- lib/que/active_record/connection.rb
|
@@ -94,11 +85,13 @@ files:
|
|
94
85
|
- lib/que/version.rb
|
95
86
|
- lib/que/worker.rb
|
96
87
|
- que.gemspec
|
97
|
-
|
88
|
+
- scripts/docker-entrypoint
|
89
|
+
- scripts/test
|
90
|
+
homepage: https://github.com/que-rb/que
|
98
91
|
licenses:
|
99
92
|
- MIT
|
100
93
|
metadata: {}
|
101
|
-
post_install_message:
|
94
|
+
post_install_message:
|
102
95
|
rdoc_options: []
|
103
96
|
require_paths:
|
104
97
|
- lib
|
@@ -109,13 +102,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
102
|
version: '0'
|
110
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
104
|
requirements:
|
112
|
-
- - "
|
105
|
+
- - ">="
|
113
106
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
107
|
+
version: '0'
|
115
108
|
requirements: []
|
116
|
-
|
117
|
-
|
118
|
-
signing_key:
|
109
|
+
rubygems_version: 3.3.6
|
110
|
+
signing_key:
|
119
111
|
specification_version: 4
|
120
112
|
summary: A PostgreSQL-based Job Queue
|
121
113
|
test_files: []
|
data/CHANGELOG.1.0.beta.md
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
### 1.0.0.beta3 (2018-05-18)
|
2
|
-
|
3
|
-
* Added support for customizing log levels for `job_worked` events (#217).
|
4
|
-
|
5
|
-
* Began logging all `job_errored` events at the `ERROR` log level.
|
6
|
-
|
7
|
-
* Fixed the Railtie when running in test mode (#214).
|
8
|
-
|
9
|
-
* Tweaked the meanings of worker-priorities and worker-count options in the CLI, to better support use cases with low worker counts (#216).
|
10
|
-
|
11
|
-
### 1.0.0.beta2 (2018-04-13)
|
12
|
-
|
13
|
-
* Fixed an incompatibility that caused the new locker to hang when using Rails in development mode (#213).
|
14
|
-
|
15
|
-
* Fixed a bug with setting the log level via the CLI when the configured logger was based on a callable (#210).
|
16
|
-
|
17
|
-
* Renamed Que.middleware to Que.job_middleware.
|
18
|
-
|
19
|
-
* Added Que.sql_middleware.
|
20
|
-
|
21
|
-
* Officially added support for Ruby 2.5.
|
22
|
-
|
23
|
-
* Internal cleanup and renamings.
|
24
|
-
|
25
|
-
### 1.0.0.beta (2017-10-25)
|
26
|
-
|
27
|
-
* **A schema upgrade to version 4 will be required for this release.** See [the migration doc](https://github.com/chanks/que/blob/master/docs/migrating.md) for information if you're upgrading from a previous release.
|
28
|
-
|
29
|
-
* Please note that this migration requires a rewrite of the jobs table, which makes it O(n) with the size of the table. If you have a very large backlog of jobs you may want to schedule downtime for this migration.
|
30
|
-
|
31
|
-
* Que's implementation has been changed from one in which worker threads hold their own PG connections and lock their own jobs to one in which a single thread (and PG connection) locks jobs through LISTEN/NOTIFY and batch polling, and passes jobs along to worker threads. This has many benefits, including:
|
32
|
-
|
33
|
-
* Jobs queued for immediate processing can be actively distributed to workers with LISTEN/NOTIFY, which is more efficient than having workers repeatedly poll for new jobs.
|
34
|
-
|
35
|
-
* When polling is necessary (to pick up jobs that are scheduled for the future or that need to be retried due to errors), jobs can be locked and fetched in batches, rather than one at a time.
|
36
|
-
|
37
|
-
* Individual workers no longer need to monopolize their own (usually idle) connections while working jobs, so Ruby processes will require fewer Postgres connections.
|
38
|
-
|
39
|
-
* PgBouncer or another external connection pool can be used for workers' connections (though not for the connection used to lock and listen for jobs).
|
40
|
-
|
41
|
-
* Other features introduced in this version include:
|
42
|
-
|
43
|
-
* Much better support for all versions of ActiveJob.
|
44
|
-
|
45
|
-
* In particular, you may (optionally) include `Que::ActiveJob::JobExtensions` into `ApplicationJob` to get support for all of Que's job helper methods.
|
46
|
-
|
47
|
-
* Custom middleware that wrap running jobs are now supported.
|
48
|
-
|
49
|
-
* Support for categorizing jobs with tags.
|
50
|
-
|
51
|
-
* Support for configuring a `maximum_retry_count` on individual job classes.
|
52
|
-
|
53
|
-
* Job configuration options are now inheritable, so job class hierarchies are more useful.
|
54
|
-
|
55
|
-
* There are now built-in models for ActiveRecord and Sequel to allow inspecting the queue easily.
|
56
|
-
|
57
|
-
* Jobs that have finished working may optionally be retained in the database indefinitely.
|
58
|
-
|
59
|
-
* To keep a job record, replace the `destroy` calls in your jobs with `finish`. `destroy` will still delete records entirely, for jobs that you don't want to keep.
|
60
|
-
|
61
|
-
* If you don't resolve a job yourself one way or another, Que will still `destroy` the job for you by default.
|
62
|
-
|
63
|
-
* Finished jobs have a timestamp set in the finished_at column.
|
64
|
-
|
65
|
-
* Jobs that have errored too many times will now be marked as expired, and won't be retried again.
|
66
|
-
|
67
|
-
* You can configure a maximum_retry_count in your job classes, to set the threshold at which a job will be marked expired. The default is 15.
|
68
|
-
|
69
|
-
* To manually mark a job as expired (and keep it in the database but not try to run it again) you can call `expire` helper in your job.
|
70
|
-
|
71
|
-
* You can now set job priority thresholds for individual workers, to ensure that there will always be space available for high-priority jobs.
|
72
|
-
|
73
|
-
* `Que.job_states` returns a list of locked jobs and the hostname/pid of the Ruby processes that have locked them.
|
74
|
-
|
75
|
-
* `Que.connection_proc=` has been added, to allow for the easy integration of custom connection pools.
|
76
|
-
|
77
|
-
* In keeping with semantic versioning, the major version is being bumped since the new implementation requires some backwards-incompatible changes. These changes include:
|
78
|
-
|
79
|
-
* Support for MRI Rubies before 2.2 has been dropped.
|
80
|
-
|
81
|
-
* Support for Postgres versions before 9.5 has been dropped (JSONB and upsert support is required).
|
82
|
-
|
83
|
-
* JRuby support has been dropped. It will be reintroduced whenever the jruby-pg gem is production-ready.
|
84
|
-
|
85
|
-
* The `que:work` rake task has been removed. Use the `que` executable instead.
|
86
|
-
|
87
|
-
* Therefore, configuring workers using QUE_* environment variables is no longer supported. Please pass the appropriate options to the `que` executable instead.
|
88
|
-
|
89
|
-
* The `mode` setter has been removed.
|
90
|
-
|
91
|
-
* To run jobs synchronously when they are enqueued (the old `:sync` behavior) you can set `Que.run_synchronously = true`.
|
92
|
-
|
93
|
-
* To start up the worker pool (the old :async behavior) you should use the `que` executable to start up a worker process. There's no longer a supported API for running workers outside of the `que` executable.
|
94
|
-
|
95
|
-
* The following methods are not meaningful under the new implementation and have been removed:
|
96
|
-
|
97
|
-
* The `Que.wake_interval` getter and setter.
|
98
|
-
|
99
|
-
* The `Que.worker_count` getter and setter.
|
100
|
-
|
101
|
-
* `Que.wake!`
|
102
|
-
|
103
|
-
* `Que.wake_all!`
|
104
|
-
|
105
|
-
* Since Que needs a dedicated Postgres connection to manage job locks, running Que through a single PG connection is no longer supported.
|
106
|
-
|
107
|
-
* It's not clear that anyone ever actually did this.
|
108
|
-
|
109
|
-
* `Que.worker_states` has been removed, as the connection that locks a job is no longer the one that the job is using to run. Its functionality has been partially replaced with `Que.job_states`.
|
110
|
-
|
111
|
-
* When using Rails, for simplicity, job attributes and keys in argument hashes are now converted to symbols when retrieved from the database, rather than being converted to instances of HashWithIndifferentAccess.
|
112
|
-
|
113
|
-
* Arguments passed to jobs are now deep-frozen, to prevent unexpected behavior when the args are mutated and the job is reenqueued.
|
114
|
-
|
115
|
-
* Since JSONB is now used to store arguments, the order of argument hashes is no longer maintained.
|
116
|
-
|
117
|
-
* It wouldn't have been a good idea to rely on this anyway.
|
118
|
-
|
119
|
-
* Calling Que.log() directly is no longer supported/recommended.
|
120
|
-
|
121
|
-
* Features marked as deprecated in the final 0.x releases have been removed.
|
122
|
-
|
123
|
-
* Finally, if you've built up your own tooling and customizations around Que, you may need to be aware of some DB schema changes made in the migration to schema version #4.
|
124
|
-
|
125
|
-
* The `job_id` column has been renamed `id` and is now the primary key. This makes it easier to manage the queue using an ActiveRecord model.
|
126
|
-
|
127
|
-
* Finished jobs are now kept in the DB, unless you explicitly call `destroy`. If you want to query the DB for only jobs that haven't finished yet, add a `WHERE finished_at IS NULL` condition to your query, or use the not_finished scope on one of the provided ORM models.
|
128
|
-
|
129
|
-
* There is now an `expired_at` timestamp column, which is set when a job reaches its maximum number of retries and will not be attempted again.
|
130
|
-
|
131
|
-
* Due to popular demand, the default queue name is now "default" rather than an empty string. The migration will move pending jobs under the "" queue to the "default" queue.
|
132
|
-
|
133
|
-
* The `last_error` column has been split in two, to `last_error_message` and `last_error_backtrace`. These two columns are now limited to 500 and 10,000 characters, respectively. The migration will split old error data correctly, and truncate it if necessary.
|
134
|
-
|
135
|
-
* Names for queues and job classes are now limited to 500 characters, which is still far longer than either of these values should reasonably be.
|
136
|
-
|
137
|
-
* There is now a `data` JSONB column which is used to support various ways of organizing jobs (setting tags on them, etc).
|
data/docs/active_job.md
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
## Using Que With ActiveJob
|
2
|
-
|
3
|
-
You can include `Que::ActiveJob::JobExtensions` into your `ApplicationJob` subclass to get support for all of Que's
|
4
|
-
[helper methods](/docs/job_helper_methods.md). These methods will become no-ops if you use a queue adapter that isn't Que, so if you like to use a different adapter in development they shouldn't interfere.
|
5
|
-
|
6
|
-
Additionally, including `Que::ActiveJob::JobExtensions` lets you define a run() method that supports keyword arguments.
|
data/docs/advanced_setup.md
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
## Advanced Setup
|
2
|
-
|
3
|
-
### Using ActiveRecord Without Rails
|
4
|
-
|
5
|
-
If you're using both Rails and ActiveRecord, the README describes how to get started with Que (which is pretty straightforward, since it includes a Railtie that handles a lot of setup for you). Otherwise, you'll need to do some manual setup.
|
6
|
-
|
7
|
-
If you're using ActiveRecord outside of Rails, you'll need to tell Que to piggyback on its connection pool after you've connected to the database:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
|
11
|
-
|
12
|
-
require 'que'
|
13
|
-
Que.connection = ActiveRecord
|
14
|
-
```
|
15
|
-
|
16
|
-
Then you can queue jobs just as you would in Rails:
|
17
|
-
|
18
|
-
```ruby
|
19
|
-
ActiveRecord::Base.transaction do
|
20
|
-
@user = User.create(params[:user])
|
21
|
-
SendRegistrationEmail.enqueue user_id: @user.id
|
22
|
-
end
|
23
|
-
```
|
24
|
-
|
25
|
-
There are other docs to read if you're using [Sequel](https://github.com/chanks/que/blob/master/docs/using_sequel.md) or [plain Postgres connections](https://github.com/chanks/que/blob/master/docs/using_plain_connections.md) (with no ORM at all) instead of ActiveRecord.
|
26
|
-
|
27
|
-
### Managing the Jobs Table
|
28
|
-
|
29
|
-
After you've connected Que to the database, you can manage the jobs table. You'll want to migrate to a specific version in a migration file, to ensure that they work the same way even when you upgrade Que in the future:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
# Update the schema to version #4.
|
33
|
-
Que.migrate! version: 4
|
34
|
-
|
35
|
-
# Remove Que's jobs table entirely.
|
36
|
-
Que.migrate! version: 0
|
37
|
-
```
|
38
|
-
|
39
|
-
There's also a helper method to clear all jobs from the jobs table:
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
Que.clear!
|
43
|
-
```
|
44
|
-
|
45
|
-
### Other Setup
|
46
|
-
|
47
|
-
Be sure to read the docs on [managing workers](https://github.com/chanks/que/blob/master/docs/managing_workers.md) for more information on using the worker pool.
|
48
|
-
|
49
|
-
You'll also want to set up [logging](https://github.com/chanks/que/blob/master/docs/logging.md) and an [error handler](https://github.com/chanks/que/blob/master/docs/error_handling.md) to track errors raised by jobs.
|