good_job 2.15.1 → 2.16.1

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: bef9bcf112b4c04ebbc2ebb05a6253bfafcf8d6b077ac177e2da7dc51beb2530
4
- data.tar.gz: c5379f8a78edf855415b67f0879e65ad469eebf73c535576d572a0069ae7feff
3
+ metadata.gz: 6f37fb872be59c7ead625a1ff54ad50d39206209c87bf11f8a88bd7f2f484676
4
+ data.tar.gz: 50c80eebdd8654894ad26ed052fa0ddfedac8dd30e100e260541d0b1d21d6951
5
5
  SHA512:
6
- metadata.gz: 6f668a1496b0a5ef3b9c0a8d126fe4b6709bcabd1cb96466fe4c8530620dffeed9ac2c10ca103773bf2a7196441d8bc8981893a4f01c91bd5cddf318d08fbf05
7
- data.tar.gz: 26f017289703d8017dd69183b425a602d1501e835b11c4552ecfca789ed43ee192d56aaed2c204ecc06343ac07908b19ad56b23d978a0cae5869a10236e75dbd
6
+ metadata.gz: c6aff64526dcc2989f14e6a7b4fe1a5be5a13df166a13c2055f10eada589f0f8d9586be7a98be94e4e16f81c55524c260cb28b52771a8f8a62064553fa426b5e
7
+ data.tar.gz: 4f64c31ecf4ff9149d35c0611b1d04158ec7ee1f92cefcbce831f1c442d551d7f406a818d4a111b7c4e848d2ecf15f66dd0968d6224f5d51c2a65394075b3237
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## [v2.16.1](https://github.com/bensheldon/good_job/tree/v2.16.1) (2022-06-18)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.16.0...v2.16.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Fix `:inline` mode with future behavior to run unscheduled jobs immediately [\#620](https://github.com/bensheldon/good_job/pull/620) ([bensheldon](https://github.com/bensheldon))
10
+ - Version check `Zeitwerk::Loader.new(warn_on_extra_files: false)` flag [\#619](https://github.com/bensheldon/good_job/pull/619) ([bensheldon](https://github.com/bensheldon))
11
+
12
+ ## [v2.16.0](https://github.com/bensheldon/good_job/tree/v2.16.0) (2022-06-17)
13
+
14
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.15.2...v2.16.0)
15
+
16
+ **Closed issues:**
17
+
18
+ - Upgrading zeitwerk to 2.6.0 causes a warning related to good\_job [\#616](https://github.com/bensheldon/good_job/issues/616)
19
+
20
+ **Merged pull requests:**
21
+
22
+ - Allow inline executor to respect scheduled jobs; deprecate old behavior. Add `GoodJob.perform_inline` [\#615](https://github.com/bensheldon/good_job/pull/615) ([bensheldon](https://github.com/bensheldon))
23
+
24
+ ## [v2.15.2](https://github.com/bensheldon/good_job/tree/v2.15.2) (2022-06-17)
25
+
26
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.15.1...v2.15.2)
27
+
28
+ **Closed issues:**
29
+
30
+ - ActiveRecord::StatementInvalid PG::ProgramLimitExceeded: ERROR: index row size 3296 exceeds btree version 4 maximum 2704 for index [\#612](https://github.com/bensheldon/good_job/issues/612)
31
+
32
+ **Merged pull requests:**
33
+
34
+ - Zeitwerk ignore `lib/active_job` [\#617](https://github.com/bensheldon/good_job/pull/617) ([bensheldon](https://github.com/bensheldon))
35
+
3
36
  ## [v2.15.1](https://github.com/bensheldon/good_job/tree/v2.15.1) (2022-05-24)
4
37
 
5
38
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v2.15.0...v2.15.1)
@@ -22,6 +55,7 @@
22
55
 
23
56
  **Implemented enhancements:**
24
57
 
58
+ - Remove ability to destroy individual Executions from Dashboard; rename "Toggle" to "Inspect" everywhere [\#601](https://github.com/bensheldon/good_job/pull/601) ([bensheldon](https://github.com/bensheldon))
25
59
  - Adds the ability to delete jobs on the dashboard; add `cleanup_discarded_jobs` option to retain discarded jobs during cleanup [\#597](https://github.com/bensheldon/good_job/pull/597) ([TAGraves](https://github.com/TAGraves))
26
60
  - Dashboard: show more details about jobs [\#575](https://github.com/bensheldon/good_job/pull/575) ([bkeepers](https://github.com/bkeepers))
27
61
 
@@ -31,7 +65,6 @@
31
65
 
32
66
  **Merged pull requests:**
33
67
 
34
- - Remove ability to destroy individual Executions from Dashboard; rename "Toggle" to "Inspect" everywhere [\#601](https://github.com/bensheldon/good_job/pull/601) ([bensheldon](https://github.com/bensheldon))
35
68
  - Disable ActiveRecord Connection Reaper in test [\#600](https://github.com/bensheldon/good_job/pull/600) ([bensheldon](https://github.com/bensheldon))
36
69
  - Update README dashboard screenshot [\#599](https://github.com/bensheldon/good_job/pull/599) ([aried3r](https://github.com/aried3r))
37
70
 
data/README.md CHANGED
@@ -59,6 +59,7 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
59
59
  - [Execute jobs async / in-process](#execute-jobs-async--in-process)
60
60
  - [Migrate to GoodJob from a different ActiveJob backend](#migrate-to-goodjob-from-a-different-activejob-backend)
61
61
  - [Monitor and preserve worked jobs](#monitor-and-preserve-worked-jobs)
62
+ - [Write tests](#write-tests)
62
63
  - [PgBouncer compatibility](#pgbouncer-compatibility)
63
64
  - [CLI HTTP health check probes](#cli-http-health-check-probes)
64
65
  - [Contribute](#contribute)
@@ -276,6 +277,7 @@ Available configuration options are:
276
277
  - `cleanup_preserved_jobs_before_seconds_ago` (integer) number of seconds to preserve jobs when using the `$ good_job cleanup_preserved_jobs` CLI command or calling `GoodJob.cleanup_preserved_jobs`. Defaults to `86400` (1 day). Can also be set with the environment variable `GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO`. _This configuration is only used when {GoodJob.preserve_job_records} is `true`._
277
278
  - `cleanup_interval_jobs` (integer) Number of jobs a Scheduler will execute before cleaning up preserved jobs. Defaults to `nil`. Can also be set with the environment variable `GOOD_JOB_CLEANUP_INTERVAL_JOBS`.
278
279
  - `cleanup_interval_seconds` (integer) Number of seconds a Scheduler will wait before cleaning up preserved jobs. Defaults to `nil`. Can also be set with the environment variable `GOOD_JOB_CLEANUP_INTERVAL_SECONDS`.
280
+ - `inline_execution_respects_schedule` (boolean) Opt-in to future behavior of inline execution respecting scheduled jobs. Defaults to `false`.
279
281
  - `logger` ([Rails Logger](https://api.rubyonrails.org/classes/ActiveSupport/Logger.html)) lets you set a custom logger for GoodJob. It should be an instance of a Rails `Logger` (Default: `Rails.logger`).
280
282
  - `preserve_job_records` (boolean) keeps job records in your database even after jobs are completed. (Default: `false`)
281
283
  - `retry_on_unhandled_error` (boolean) causes jobs to be re-queued and retried if they raise an instance of `StandardError`. Be advised this may lead to jobs being repeated infinitely ([see below for more on retries](#retries)). Instances of `Exception`, like SIGINT, will *always* be retried, regardless of this attribute’s value. (Default: `true`)
@@ -878,6 +880,23 @@ It is also necessary to destroy these preserved jobs from the database after a c
878
880
  bundle exec good_job cleanup_preserved_jobs --before-seconds-ago=86400
879
881
  ```
880
882
 
883
+ ### Write tests
884
+
885
+ By default, GoodJob uses its inline adapter in the test environment; the inline adapter is designed for the test environment. When enquing a job with GoodJob's inline adapter, the job will be executed immediately on the current thread; unhandled exceptions will be raised.
886
+
887
+ In GoodJob 2.0, the inline adapter will execute future scheduled jobs immediately. In the next major release, GoodJob 3.0, the inline adapter will not execute future scheduled jobs and instead enqueue them in the database.
888
+
889
+ To opt into this behavior immediately set: `config.good_job.inline_execution_respects_schedule = true`
890
+
891
+ To perform jobs inline at any time, use `GoodJob.perform_inline`. For example, using time helpers within an integration test:
892
+
893
+ ```ruby
894
+ MyJob.set(wait: 10.minutes).perform_later
895
+ travel_to(15.minutes.from_now) { GoodJob.perform_inline }
896
+ ```
897
+
898
+ _Note: Rails `travel`/`travel_to` time helpers do not have millisecond precision, so you must leave at least 1 second between the schedule and time traveling for the job to be executed. This [behavior may change in Rails 7.1](https://github.com/rails/rails/pull/44088)._
899
+
881
900
  ### PgBouncer compatibility
882
901
 
883
902
  GoodJob is not compatible with PgBouncer in _transaction_ mode, but is compatible with PgBouncer's _connection_ mode. GoodJob uses connection-based advisory locks and LISTEN/NOTIFY, both of which require full database connections.
@@ -62,19 +62,48 @@ module GoodJob
62
62
  # @param timestamp [Integer, nil] the epoch time to perform the job
63
63
  # @return [GoodJob::Execution]
64
64
  def enqueue_at(active_job, timestamp)
65
+ scheduled_at = timestamp ? Time.zone.at(timestamp) : nil
66
+
67
+ if execute_inline?
68
+ future_scheduled = scheduled_at && scheduled_at > Time.current
69
+ will_execute_inline = !future_scheduled || (future_scheduled && !@configuration.inline_execution_respects_schedule?)
70
+ end
71
+
65
72
  execution = GoodJob::Execution.enqueue(
66
73
  active_job,
67
- scheduled_at: timestamp ? Time.zone.at(timestamp) : nil,
68
- create_with_advisory_lock: execute_inline?
74
+ scheduled_at: scheduled_at,
75
+ create_with_advisory_lock: will_execute_inline
69
76
  )
70
77
 
71
- if execute_inline?
78
+ if will_execute_inline
79
+ if future_scheduled && !@configuration.inline_execution_respects_schedule?
80
+ ActiveSupport::Deprecation.warn(<<~DEPRECATION)
81
+ In the next major release, GoodJob will not *inline* execute
82
+ future-scheduled jobs.
83
+
84
+ To opt into this behavior immediately set:
85
+ `config.good_job.inline_execution_respects_schedule = true`
86
+
87
+ To perform jobs inline at any time, use `GoodJob.perform_inline`.
88
+
89
+ For example, using time helpers within an integration test:
90
+
91
+ ```
92
+ MyJob.set(wait: 10.minutes).perform_later
93
+ travel_to(15.minutes.from_now) { GoodJob.perform_inline }
94
+ ```
95
+
96
+ Note: Rails `travel`/`travel_to` time helpers do not have millisecond
97
+ precision, so you must leave at least 1 second between the schedule
98
+ and time traveling for the job to be executed.
99
+ DEPRECATION
100
+ end
101
+
72
102
  begin
73
103
  result = execution.perform
74
104
  ensure
75
105
  execution.advisory_unlock
76
106
  end
77
-
78
107
  raise result.unhandled_error if result.unhandled_error
79
108
  else
80
109
  job_state = { queue_name: execution.queue_name }
@@ -119,6 +119,10 @@ module GoodJob
119
119
  end
120
120
  end
121
121
 
122
+ def inline_execution_respects_schedule?
123
+ !!rails_config[:inline_execution_respects_schedule]
124
+ end
125
+
122
126
  # The maximum number of future-scheduled jobs to store in memory.
123
127
  # Storing future-scheduled jobs in memory reduces execution latency
124
128
  # at the cost of increased memory usage. 10,000 stored jobs = ~20MB.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module GoodJob
3
3
  # GoodJob gem version.
4
- VERSION = '2.15.1'
4
+ VERSION = '2.16.1'
5
5
  end
data/lib/good_job.rb CHANGED
@@ -4,11 +4,12 @@ require "active_job"
4
4
  require "active_job/queue_adapters"
5
5
 
6
6
  require "zeitwerk"
7
- Zeitwerk::Loader.for_gem.tap do |loader|
7
+ zeitwerk_options = Gem::Version.new(Zeitwerk::VERSION) >= Gem::Version.new("2.6.0") ? { warn_on_extra_files: false } : {}
8
+ Zeitwerk::Loader.for_gem(**zeitwerk_options).tap do |loader|
8
9
  loader.inflector.inflect({
9
10
  "cli" => "CLI",
10
11
  })
11
- loader.ignore(File.join(File.dirname(__FILE__), "generators"))
12
+ loader.ignore("#{__dir__}/generators")
12
13
  loader.setup
13
14
  end
14
15
 
@@ -151,6 +152,20 @@ module GoodJob
151
152
  end
152
153
  end
153
154
 
155
+ # Perform all queued jobs in the current thread.
156
+ # This is primarily intended for usage in a test environment.
157
+ # Unhandled job errors will be raised.
158
+ # @param queue_string [String] Queues to execute jobs from
159
+ # @return [void]
160
+ def self.perform_inline(queue_string = "*")
161
+ job_performer = JobPerformer.new(queue_string)
162
+ loop do
163
+ result = job_performer.next
164
+ break unless result
165
+ raise result.unhandled_error if result.unhandled_error
166
+ end
167
+ end
168
+
154
169
  def self._executables
155
170
  [].concat(
156
171
  CronManager.instances,
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: 2.15.1
4
+ version: 2.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sheldon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-24 00:00:00.000000000 Z
11
+ date: 2022-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob