good_job 3.15.1 → 3.15.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95ede69036445ced25b5afed25912ce509a171d7311e7a5c2c91d3b9615c0482
4
- data.tar.gz: 141500358218a98d7e84b5415b1f1d8afb92243a5695928370b5497906716ae3
3
+ metadata.gz: 4674d611fd466270ee2bb79b4763848bced81ed16ae227dc05e0daca00b5672e
4
+ data.tar.gz: 40dda31aa1e21e6b16e4f2582354d572af271ebe270b80e6cbfceec95873f5da
5
5
  SHA512:
6
- metadata.gz: 997b09e9a348d9b11fd67521a54222909f4e495ecede63bcc253473e4a8544fdaa40f3e77171dbbb35692f8f1f77290b51cbf80bfc50817422f94efdbed3c83a
7
- data.tar.gz: f64e80caca4d1c31449af26e146b77a0d71c53ca09bc2c8370c0190daafe0565380d0bc60ca42fb20a84e5be41c50c23b7f4b4c0674f69a3bff47c5c43fcf537
6
+ metadata.gz: 73ae44f8b88e70d4cfd98473920af572320157432f121b437f99718ca2182fa88d98b7f3dd4a3aec0319b6f2ddd51eb5eed1fe0290f94b605a4b9b7fedf53cc6
7
+ data.tar.gz: 932c23ebe5722a3a8d7638db77bfeefd350c219a071b8b96982cd19ad78319c2ddd3f7b178d3ebb59b7d670caf7b265c01b254c2481d13a7a6f0521f0d172c82
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.15.2](https://github.com/bensheldon/good_job/tree/v3.15.2) (2023-04-19)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.15.1...v3.15.2)
6
+
7
+ **Closed issues:**
8
+
9
+ - Cleaning up preserved jobs giving me timeout [\#933](https://github.com/bensheldon/good_job/issues/933)
10
+ - uninitialized constant GoodJob::ActiveJobJob \(NameError\) [\#932](https://github.com/bensheldon/good_job/issues/932)
11
+
12
+ **Merged pull requests:**
13
+
14
+ - Use batched queries in `GoodJob::self.cleanup_preserved_jobs` [\#934](https://github.com/bensheldon/good_job/pull/934) ([bensheldon](https://github.com/bensheldon))
15
+ - 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))
16
+
3
17
  ## [v3.15.1](https://github.com/bensheldon/good_job/tree/v3.15.1) (2023-04-17)
4
18
 
5
19
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.15.0...v3.15.1)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module GoodJob
3
3
  # GoodJob gem version.
4
- VERSION = '3.15.1'
4
+ VERSION = '3.15.2'
5
5
  end
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
- old_jobs = GoodJob::Job.where('finished_at <= ?', timestamp)
172
- old_jobs = old_jobs.succeeded unless include_discarded
173
- deleted_executions_count = GoodJob::Execution.where(job: old_jobs).delete_all
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
- old_batches = GoodJob::BatchRecord.where('finished_at <= ?', timestamp)
177
- old_batches = old_batches.succeeded unless include_discarded
178
- deleted_batches_count = old_batches.delete_all
179
- else
180
- deleted_batches_count = 0
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.1
4
+ version: 3.15.2
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-17 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob