good_job 3.15.1 → 3.15.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/lib/good_job/dependencies.rb +5 -26
- data/lib/good_job/engine.rb +7 -12
- data/lib/good_job/version.rb +1 -1
- data/lib/good_job.rb +20 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85c6903e5f8838cb72f4687e364fa20cf9c461f0c4b79412bb8b61549bbf6333
|
4
|
+
data.tar.gz: d00fecc5a4fe561bc1a7f21a79e46245cb5ab603fafbbb4369344395c9c0fac0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1116f1e94e07b62bc316a3ec76a1b0768d22b5a511a65cf18e40bc13d4e8c25290c7c879d5cdfea1f1a988e3809b130462b57bd25a7c2405b0152cbe9434f51
|
7
|
+
data.tar.gz: 227c89386f14a783260fff68c55f0f4b0d10db331ab705b922f02fdce79a8ec4cf0f969e554f02e55f030dbcda6efbd9439bcaafd7bc471028c35375a7b58ccf
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v3.15.3](https://github.com/bensheldon/good_job/tree/v3.15.3) (2023-04-22)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v3.15.2...v3.15.3)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Eagerly autoload `ActiveJob::Base`; clean up framework deferred-loading logic to use nested `on_load` blocks [\#931](https://github.com/bensheldon/good_job/pull/931) ([bensheldon](https://github.com/bensheldon))
|
10
|
+
|
11
|
+
## [v3.15.2](https://github.com/bensheldon/good_job/tree/v3.15.2) (2023-04-19)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v3.15.1...v3.15.2)
|
14
|
+
|
15
|
+
**Closed issues:**
|
16
|
+
|
17
|
+
- Cleaning up preserved jobs giving me timeout [\#933](https://github.com/bensheldon/good_job/issues/933)
|
18
|
+
- uninitialized constant GoodJob::ActiveJobJob \(NameError\) [\#932](https://github.com/bensheldon/good_job/issues/932)
|
19
|
+
|
20
|
+
**Merged pull requests:**
|
21
|
+
|
22
|
+
- Use batched queries in `GoodJob::self.cleanup_preserved_jobs` [\#934](https://github.com/bensheldon/good_job/pull/934) ([bensheldon](https://github.com/bensheldon))
|
23
|
+
- Bump nokogiri from 1.14.2 to 1.14.3 [\#926](https://github.com/bensheldon/good_job/pull/926) ([dependabot[bot]](https://github.com/apps/dependabot))
|
24
|
+
|
3
25
|
## [v3.15.1](https://github.com/bensheldon/good_job/tree/v3.15.1) (2023-04-17)
|
4
26
|
|
5
27
|
[Full Changelog](https://github.com/bensheldon/good_job/compare/v3.15.0...v3.15.1)
|
@@ -6,40 +6,19 @@ module GoodJob # :nodoc:
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
|
-
|
10
|
-
# @!scope class
|
11
|
-
# Whether Railtie.after_initialize has been called yet (default: +false+).
|
12
|
-
# This will be set on but before +Rails.application.initialize?+ is +true+.
|
13
|
-
# @return [Boolean]
|
14
|
-
mattr_accessor :_rails_after_initialize_hook_called, default: false
|
15
|
-
|
16
|
-
# @!attribute [rw] _active_job_loaded
|
17
|
-
# @!scope class
|
18
|
-
# Whether ActiveJob has loaded (default: +false+).
|
19
|
-
# @return [Boolean]
|
20
|
-
mattr_accessor :_active_job_loaded, default: false
|
21
|
-
|
22
|
-
# @!attribute [rw] _active_record_loaded
|
23
|
-
# @!scope class
|
24
|
-
# Whether ActiveRecord has loaded (default: +false+).
|
25
|
-
# @return [Boolean]
|
26
|
-
mattr_accessor :_active_record_loaded, default: false
|
9
|
+
mattr_accessor :_framework_ready, default: false
|
27
10
|
end
|
28
11
|
|
29
12
|
class_methods do
|
30
|
-
# Whether
|
31
|
-
# @return [Boolean]
|
13
|
+
# Whether Rails framework has sufficiently initialized to enable Async execution.
|
32
14
|
def async_ready?
|
33
|
-
Rails.application.initialized? ||
|
34
|
-
_rails_after_initialize_hook_called &&
|
35
|
-
_active_job_loaded &&
|
36
|
-
_active_record_loaded
|
37
|
-
)
|
15
|
+
Rails.application.initialized? || _framework_ready
|
38
16
|
end
|
39
17
|
|
40
|
-
def
|
18
|
+
def _start_async_adapters
|
41
19
|
return unless async_ready?
|
42
20
|
|
21
|
+
ActiveJob::Base.queue_adapter # Ensure Active Job is initialized
|
43
22
|
GoodJob::Adapter.instances
|
44
23
|
.select(&:execute_async?)
|
45
24
|
.reject(&:async_started?)
|
data/lib/good_job/engine.rb
CHANGED
@@ -37,26 +37,21 @@ module GoodJob
|
|
37
37
|
|
38
38
|
initializer "good_job.start_async" do
|
39
39
|
# This hooks into the hookable places during Rails boot, which is unfortunately not Rails.application.initialized?
|
40
|
-
# If an Adapter is initialized during boot, we want to want to start
|
40
|
+
# If an Adapter is initialized during boot, we want to want to start async executors once the framework dependencies have loaded.
|
41
41
|
# When exactly that happens is out of our control because gems or application code may touch things earlier than expected.
|
42
42
|
# For example, as of Rails 6.1, if an ActiveRecord model is touched during boot, that triggers ActiveRecord to load,
|
43
43
|
# which touches DestroyAssociationAsyncJob, which loads ActiveJob, which may initialize a GoodJob::Adapter, all of which
|
44
44
|
# happens _before_ ActiveRecord finishes loading. GoodJob will deadlock if an async executor is started in the middle of
|
45
45
|
# ActiveRecord loading.
|
46
|
-
|
47
46
|
config.after_initialize do
|
48
47
|
ActiveSupport.on_load(:active_record) do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
GoodJob._active_job_loaded = true
|
55
|
-
GoodJob.start_async_adapters
|
48
|
+
ActiveSupport.on_load(:active_job) do
|
49
|
+
GoodJob._framework_ready = true
|
50
|
+
GoodJob._start_async_adapters
|
51
|
+
end
|
52
|
+
GoodJob._start_async_adapters
|
56
53
|
end
|
57
|
-
|
58
|
-
GoodJob._rails_after_initialize_hook_called = true
|
59
|
-
GoodJob.start_async_adapters
|
54
|
+
GoodJob._start_async_adapters
|
60
55
|
end
|
61
56
|
end
|
62
57
|
end
|
data/lib/good_job/version.rb
CHANGED
data/lib/good_job.rb
CHANGED
@@ -162,22 +162,33 @@ module GoodJob
|
|
162
162
|
# destroy old records and preserve space in your database.
|
163
163
|
# @param older_than [nil,Numeric,ActiveSupport::Duration] Jobs older than this will be destroyed (default: +86400+).
|
164
164
|
# @return [Integer] Number of job execution records and batches that were destroyed.
|
165
|
-
def self.cleanup_preserved_jobs(older_than: nil)
|
165
|
+
def self.cleanup_preserved_jobs(older_than: nil, in_batches_of: 1_000)
|
166
166
|
older_than ||= GoodJob.configuration.cleanup_preserved_jobs_before_seconds_ago
|
167
167
|
timestamp = Time.current - older_than
|
168
168
|
include_discarded = GoodJob.configuration.cleanup_discarded_jobs?
|
169
169
|
|
170
170
|
ActiveSupport::Notifications.instrument("cleanup_preserved_jobs.good_job", { older_than: older_than, timestamp: timestamp }) do |payload|
|
171
|
-
|
172
|
-
|
173
|
-
|
171
|
+
deleted_executions_count = 0
|
172
|
+
deleted_batches_count = 0
|
173
|
+
|
174
|
+
jobs_query = GoodJob::Job.where('finished_at <= ?', timestamp).order(finished_at: :asc).limit(in_batches_of)
|
175
|
+
jobs_query = jobs_query.succeeded unless include_discarded
|
176
|
+
loop do
|
177
|
+
deleted = GoodJob::Execution.where(job: jobs_query).delete_all
|
178
|
+
break if deleted.zero?
|
179
|
+
|
180
|
+
deleted_executions_count += deleted
|
181
|
+
end
|
174
182
|
|
175
183
|
if GoodJob::BatchRecord.migrated?
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
184
|
+
batches_query = GoodJob::BatchRecord.where('finished_at <= ?', timestamp).limit(in_batches_of)
|
185
|
+
batches_query = batches_query.succeeded unless include_discarded
|
186
|
+
loop do
|
187
|
+
deleted = batches_query.delete_all
|
188
|
+
break if deleted.zero?
|
189
|
+
|
190
|
+
deleted_batches_count += deleted
|
191
|
+
end
|
181
192
|
end
|
182
193
|
|
183
194
|
payload[:destroyed_executions_count] = deleted_executions_count
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: good_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.15.
|
4
|
+
version: 3.15.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Sheldon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -461,7 +461,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
461
461
|
- !ruby/object:Gem::Version
|
462
462
|
version: '0'
|
463
463
|
requirements: []
|
464
|
-
rubygems_version: 3.4.
|
464
|
+
rubygems_version: 3.4.10
|
465
465
|
signing_key:
|
466
466
|
specification_version: 4
|
467
467
|
summary: A multithreaded, Postgres-based ActiveJob backend for Ruby on Rails
|