inst-jobs 3.0.12 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/delayed/backend/base.rb +8 -2
- data/lib/delayed/lifecycle.rb +2 -1
- data/lib/delayed/server.rb +1 -1
- data/lib/delayed/settings.rb +2 -0
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/worker.rb +3 -3
- data/spec/delayed/worker_spec.rb +4 -3
- data/spec/shared/shared_backend.rb +17 -0
- data/spec/spec_helper.rb +3 -3
- 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: 0ea5fb9db3338718560d2107fd348ca95077e2b1f98490d33a8f61ecf686d7dd
|
4
|
+
data.tar.gz: 17ae33dac196625a7d194c51b609f1c7e98b6ce8917898b2a03b283b9784c96c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20ad04cef57908281160729d47e4e9ae0a86b2c75c7200cdb0467c23b69dd32d634b1f6c886cda42209d1a2f794acf2461f0b69f82f4fe8571a999c93b35f277
|
7
|
+
data.tar.gz: 874f268caddfa09f160dd3eb05fa7d9be3d04fb667e23da32d6cce5901d6e45321e203db83830ad4d40986119656453b9e63f3da65f654f302150a4c95286fb6
|
data/lib/delayed/backend/base.rb
CHANGED
@@ -86,8 +86,12 @@ module Delayed
|
|
86
86
|
kwargs.merge!(n_strand_options(full_strand_name, num_strands))
|
87
87
|
end
|
88
88
|
|
89
|
+
job = nil
|
90
|
+
|
89
91
|
if singleton
|
90
|
-
|
92
|
+
Delayed::Worker.lifecycle.run_callbacks(:create, kwargs) do
|
93
|
+
job = create(**kwargs)
|
94
|
+
end
|
91
95
|
elsif batches && strand.nil? && run_at.nil?
|
92
96
|
batch_enqueue_args = kwargs.slice(*self.batch_enqueue_args)
|
93
97
|
batches[batch_enqueue_args] << kwargs
|
@@ -95,7 +99,9 @@ module Delayed
|
|
95
99
|
else
|
96
100
|
raise ArgumentError, "on_conflict can only be provided with singleton" if kwargs[:on_conflict]
|
97
101
|
|
98
|
-
|
102
|
+
Delayed::Worker.lifecycle.run_callbacks(:create, kwargs) do
|
103
|
+
job = create(**kwargs)
|
104
|
+
end
|
99
105
|
end
|
100
106
|
|
101
107
|
JobTracking.job_created(job)
|
data/lib/delayed/lifecycle.rb
CHANGED
@@ -5,6 +5,7 @@ module Delayed
|
|
5
5
|
|
6
6
|
class Lifecycle
|
7
7
|
EVENTS = {
|
8
|
+
create: [:args],
|
8
9
|
error: %i[worker job exception],
|
9
10
|
exceptional_exit: %i[worker exception],
|
10
11
|
execute: [:worker],
|
@@ -76,7 +77,7 @@ module Delayed
|
|
76
77
|
def execute(*args, &block)
|
77
78
|
@before.each { |c| c.call(*args) }
|
78
79
|
result = @around.call(*args, &block)
|
79
|
-
@after.each { |c| c.call(*args) }
|
80
|
+
@after.each { |c| c.call(*args, result: result) }
|
80
81
|
result
|
81
82
|
end
|
82
83
|
|
data/lib/delayed/server.rb
CHANGED
@@ -16,7 +16,7 @@ module Delayed
|
|
16
16
|
# Rails will take care of establishing the DB connection for us if there is
|
17
17
|
# an application present
|
18
18
|
if using_active_record? && !ActiveRecord::Base.connected?
|
19
|
-
ActiveRecord::Base.establish_connection(ENV
|
19
|
+
ActiveRecord::Base.establish_connection(ENV.fetch("DATABASE_URL", nil))
|
20
20
|
end
|
21
21
|
|
22
22
|
@allow_update = args.length.positive? && args[0][:update]
|
data/lib/delayed/settings.rb
CHANGED
@@ -33,6 +33,7 @@ module Delayed
|
|
33
33
|
|
34
34
|
SETTINGS_WITH_ARGS = %i[
|
35
35
|
job_detailed_log_format
|
36
|
+
job_short_log_format
|
36
37
|
num_strands
|
37
38
|
].freeze
|
38
39
|
|
@@ -137,6 +138,7 @@ module Delayed
|
|
137
138
|
self.job_detailed_log_format = lambda { |job|
|
138
139
|
job.to_json(include_root: false, only: %w[tag strand singleton priority attempts created_at max_attempts source])
|
139
140
|
}
|
141
|
+
self.job_short_log_format = ->(_job) { "" }
|
140
142
|
|
141
143
|
# Send workers KILL after QUIT if they haven't exited within the
|
142
144
|
# slow_exit_timeout
|
data/lib/delayed/version.rb
CHANGED
data/lib/delayed/worker.rb
CHANGED
@@ -220,7 +220,7 @@ module Delayed
|
|
220
220
|
end
|
221
221
|
job.destroy
|
222
222
|
end
|
223
|
-
logger.info("Completed #{log_job(job)} #{format('%.0fms', (runtime * 1000))}")
|
223
|
+
logger.info("Completed #{log_job(job, :short)} #{format('%.0fms', (runtime * 1000))}")
|
224
224
|
end
|
225
225
|
rescue ::Delayed::RetriableError => e
|
226
226
|
can_retry = job.attempts + 1 < job.inferred_max_attempts
|
@@ -269,14 +269,14 @@ module Delayed
|
|
269
269
|
when :long
|
270
270
|
"#{job.full_name} #{Settings.job_detailed_log_format.call(job)}"
|
271
271
|
else
|
272
|
-
job.full_name
|
272
|
+
"#{job.full_name} #{Settings.job_short_log_format.call(job)}".strip
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
276
276
|
# set up the session context information, so that it gets logged with the job log lines
|
277
277
|
# also set up a unique tmpdir, which will get removed at the end of the job.
|
278
278
|
def configure_for_job(job)
|
279
|
-
previous_tmpdir = ENV
|
279
|
+
previous_tmpdir = ENV.fetch("TMPDIR", nil)
|
280
280
|
|
281
281
|
self.class.running_job(job) do
|
282
282
|
dir = Dir.mktmpdir("job-#{job.id}-#{name.gsub(/[^\w.]/, '.')}-")
|
data/spec/delayed/worker_spec.rb
CHANGED
@@ -85,13 +85,14 @@ describe Delayed::Worker do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it "logging format can be changed with settings" do
|
88
|
-
Delayed::Settings.job_detailed_log_format = ->(job) { "override format #{job.strand}" }
|
88
|
+
Delayed::Settings.job_detailed_log_format = ->(job) { "override format detailed #{job.strand}" }
|
89
|
+
Delayed::Settings.job_short_log_format = ->(_job) { "override format short" }
|
89
90
|
payload = double(perform: nil)
|
90
91
|
job = Delayed::Job.new(payload_object: payload, priority: 25, strand: "test_jobs")
|
91
92
|
short_log_format = subject.log_job(job, :short)
|
92
|
-
expect(short_log_format).to eq("RSpec::Mocks::Double")
|
93
|
+
expect(short_log_format).to eq("RSpec::Mocks::Double override format short")
|
93
94
|
long_format = subject.log_job(job, :long)
|
94
|
-
expect(long_format).to eq("RSpec::Mocks::Double override format test_jobs")
|
95
|
+
expect(long_format).to eq("RSpec::Mocks::Double override format detailed test_jobs")
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|
@@ -35,6 +35,23 @@ shared_examples_for "a backend" do
|
|
35
35
|
expect(Delayed::Job.jobs_count(:current)).to eq(1)
|
36
36
|
end
|
37
37
|
|
38
|
+
it "triggers the lifecycle event around the create" do
|
39
|
+
called = false
|
40
|
+
created_job = nil
|
41
|
+
|
42
|
+
Delayed::Worker.lifecycle.after(:create) do |_, result:|
|
43
|
+
called = true
|
44
|
+
created_job = result
|
45
|
+
end
|
46
|
+
|
47
|
+
job = SimpleJob.new
|
48
|
+
Delayed::Job.enqueue(job)
|
49
|
+
|
50
|
+
expect(called).to be_truthy
|
51
|
+
expect(created_job).to be_kind_of Delayed::Job
|
52
|
+
expect(created_job.tag).to eq "SimpleJob#perform"
|
53
|
+
end
|
54
|
+
|
38
55
|
it "is able to set priority when enqueuing items" do
|
39
56
|
@job = Delayed::Job.enqueue SimpleJob.new, priority: 5
|
40
57
|
expect(@job.priority).to eq(5)
|
data/spec/spec_helper.rb
CHANGED
@@ -47,14 +47,14 @@ RSpec::Core::ExampleGroup.include(NoYamlDump)
|
|
47
47
|
|
48
48
|
ENV["TEST_ENV_NUMBER"] ||= "1"
|
49
49
|
ENV["TEST_DB_HOST"] ||= "localhost"
|
50
|
-
ENV["TEST_DB_DATABASE"] ||= "inst-jobs-test-#{ENV
|
50
|
+
ENV["TEST_DB_DATABASE"] ||= "inst-jobs-test-#{ENV.fetch('TEST_ENV_NUMBER', nil)}"
|
51
51
|
|
52
52
|
connection_config = {
|
53
53
|
adapter: :postgresql,
|
54
54
|
host: ENV["TEST_DB_HOST"].presence,
|
55
55
|
encoding: "utf8",
|
56
|
-
username: ENV
|
57
|
-
database: ENV
|
56
|
+
username: ENV.fetch("TEST_DB_USERNAME", nil),
|
57
|
+
database: ENV.fetch("TEST_DB_DATABASE", nil),
|
58
58
|
min_messages: "notice",
|
59
59
|
# Ensure the pool is big enough the deadlock tests don't get starved for connections by rails instead
|
60
60
|
pool: 20
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-05-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|