delayed 0.5.4 → 0.5.5
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.
- checksums.yaml +4 -4
- data/lib/delayed/active_job_adapter.rb +1 -1
- data/lib/delayed/worker.rb +24 -26
- data/spec/delayed/active_job_adapter_spec.rb +13 -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: ae36c9e652d4fb6ce28f8897b0e7b03b7777ce9907a74973924111b735bca3ae
|
4
|
+
data.tar.gz: 0d4c27d0bf1f7e256fa85914086a0711c6406b4be5e88f211eccbd921c001718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbae79e450983c1dd968b5f9959b4497758c32cc2c21a45ecea5b41dc1d7829fac2699d0a8cea635369d276eaec5b07ce8d7fa292674578ff62690823bc163fc
|
7
|
+
data.tar.gz: df37746eee87f40792499e02421f82a2fc4afa4317e168bdb440f3bed1ba737c761469092098f99e2aa3fb163f50981e6b19a83a4859e91871ac8f046363f630
|
@@ -17,7 +17,7 @@ module Delayed
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def _enqueue(job, opts = {})
|
20
|
-
if job.class.respond_to?(:enqueue_after_transaction_commit) && job.class.enqueue_after_transaction_commit
|
20
|
+
if job.class.respond_to?(:enqueue_after_transaction_commit) && job.class.enqueue_after_transaction_commit == :always
|
21
21
|
raise UnsafeEnqueueError, "The ':delayed' ActiveJob adapter is not compatible with enqueue_after_transaction_commit"
|
22
22
|
end
|
23
23
|
|
data/lib/delayed/worker.rb
CHANGED
@@ -89,22 +89,17 @@ module Delayed
|
|
89
89
|
# Exit early if interrupted.
|
90
90
|
def work_off(num = 100)
|
91
91
|
success = Concurrent::AtomicFixnum.new(0)
|
92
|
-
|
92
|
+
total = 0
|
93
93
|
|
94
|
-
num
|
94
|
+
while total < num
|
95
95
|
jobs = reserve_jobs
|
96
96
|
break if jobs.empty?
|
97
97
|
|
98
|
+
total += jobs.length
|
98
99
|
pool = Concurrent::FixedThreadPool.new(jobs.length)
|
99
100
|
jobs.each do |job|
|
100
101
|
pool.post do
|
101
|
-
|
102
|
-
if run_job(job)
|
103
|
-
success.increment
|
104
|
-
else
|
105
|
-
failure.increment
|
106
|
-
end
|
107
|
-
end
|
102
|
+
success.increment if run_job(job)
|
108
103
|
end
|
109
104
|
end
|
110
105
|
|
@@ -114,7 +109,7 @@ module Delayed
|
|
114
109
|
break if stop? # leave if we're exiting
|
115
110
|
end
|
116
111
|
|
117
|
-
[success,
|
112
|
+
[success.value, total - success.value]
|
118
113
|
end
|
119
114
|
|
120
115
|
def run_thread_callbacks(job, &block)
|
@@ -122,30 +117,33 @@ module Delayed
|
|
122
117
|
end
|
123
118
|
|
124
119
|
def run(job)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
job.
|
120
|
+
run_thread_callbacks(job) do
|
121
|
+
metadata = {
|
122
|
+
status: 'RUNNING',
|
123
|
+
name: job.name,
|
124
|
+
run_at: job.run_at,
|
125
|
+
created_at: job.created_at,
|
126
|
+
priority: job.priority,
|
127
|
+
queue: job.queue,
|
128
|
+
attempts: job.attempts,
|
129
|
+
enqueued_for: (Time.current - job.created_at).round,
|
130
|
+
}
|
131
|
+
job_say job, metadata.to_json
|
132
|
+
run_time = Benchmark.realtime do
|
133
|
+
Timeout.timeout(max_run_time(job).to_i, WorkerTimeout) do
|
134
|
+
job.invoke_job
|
135
|
+
end
|
136
|
+
job.destroy
|
139
137
|
end
|
140
|
-
job
|
138
|
+
job_say job, format('COMPLETED after %.4f seconds', run_time)
|
141
139
|
end
|
142
|
-
job_say job, format('COMPLETED after %.4f seconds', run_time)
|
143
140
|
true # did work
|
144
141
|
rescue DeserializationError => e
|
145
142
|
job_say job, "FAILED permanently with #{e.class.name}: #{e.message}", 'error'
|
146
143
|
|
147
144
|
job.error = e
|
148
145
|
failed(job)
|
146
|
+
false # work failed
|
149
147
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
150
148
|
self.class.lifecycle.run_callbacks(:error, self, job) { handle_failed_job(job, e) }
|
151
149
|
false # work failed
|
@@ -288,16 +288,27 @@ RSpec.describe Delayed::ActiveJobAdapter do
|
|
288
288
|
end
|
289
289
|
|
290
290
|
if ActiveJob.gem_version.release >= Gem::Version.new('7.2')
|
291
|
-
context 'when the given job sets enqueue_after_transaction_commit to
|
291
|
+
context 'when the given job sets enqueue_after_transaction_commit to :always' do
|
292
292
|
before do
|
293
293
|
JobClass.include ActiveJob::EnqueueAfterTransactionCommit # normally run in an ActiveJob railtie
|
294
|
-
JobClass.enqueue_after_transaction_commit =
|
294
|
+
JobClass.enqueue_after_transaction_commit = :always
|
295
295
|
end
|
296
296
|
|
297
297
|
it 'raises an exception on enqueue' do
|
298
298
|
expect { JobClass.perform_later }.to raise_error(Delayed::ActiveJobAdapter::UnsafeEnqueueError)
|
299
299
|
end
|
300
300
|
end
|
301
|
+
|
302
|
+
context 'when the given job sets enqueue_after_transaction_commit to :never' do
|
303
|
+
before do
|
304
|
+
JobClass.include ActiveJob::EnqueueAfterTransactionCommit # normally run in an ActiveJob railtie
|
305
|
+
JobClass.enqueue_after_transaction_commit = :never
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'does not raises an exception on enqueue' do
|
309
|
+
expect { JobClass.perform_later }.not_to raise_error(Delayed::ActiveJobAdapter::UnsafeEnqueueError)
|
310
|
+
end
|
311
|
+
end
|
301
312
|
end
|
302
313
|
|
303
314
|
context 'when using the ActiveJob test adapter' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Griffith
|
@@ -19,7 +19,7 @@ authors:
|
|
19
19
|
autorequire:
|
20
20
|
bindir: bin
|
21
21
|
cert_chain: []
|
22
|
-
date: 2024-
|
22
|
+
date: 2024-08-13 00:00:00.000000000 Z
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
name: activerecord
|