good_job 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -11
- data/README.md +13 -12
- data/exe/good_job +3 -2
- data/lib/active_job/queue_adapters/good_job_adapter.rb +0 -4
- data/lib/good_job/adapter.rb +20 -6
- data/lib/good_job/cli.rb +16 -4
- data/lib/good_job/configuration.rb +23 -31
- data/lib/good_job/job_performer.rb +1 -1
- data/lib/good_job/multi_scheduler.rb +1 -1
- data/lib/good_job/notifier.rb +1 -1
- data/lib/good_job/poller.rb +2 -2
- data/lib/good_job/scheduler.rb +21 -3
- data/lib/good_job/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68ed9e19332edf1b6aa736b94980c1cc6eb08a3dbee67efad71852ed69220d23
|
4
|
+
data.tar.gz: bdf36f6d86f203de02dd647bd3a245564645e18331f97dda6dcca748876153d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ecb2b42f43865aa9f9b1677438d727ff2c74ec003acd739fde3688d50dfc72e23bf61ab9cf8b12de519e31c56142a5ba79bbfa27bf09db74d829e95a1b11e30
|
7
|
+
data.tar.gz: f9c2038d1e4688cd83d23b0530071a447ee0b1692d7857a5e72b4814d8fb56496aca3aceb63b340542e518e8d0e9eeb29bf5a0ecf6d7f7da18825796cc6bee26
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [v1.
|
3
|
+
## [v1.9.0](https://github.com/bensheldon/good_job/tree/v1.9.0) (2021-04-16)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.8.0...v1.9.0)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Add `async_server` option to run async only in Rails web server process [\#230](https://github.com/bensheldon/good_job/pull/230) ([bensheldon](https://github.com/bensheldon))
|
10
|
+
- FreeBSD startup script [\#221](https://github.com/bensheldon/good_job/pull/221) ([lauer](https://github.com/lauer))
|
11
|
+
|
12
|
+
**Fixed bugs:**
|
13
|
+
|
14
|
+
- Fix instrumentation of GoodJob::Poller finished\_timer\_task event [\#233](https://github.com/bensheldon/good_job/pull/233) ([bensheldon](https://github.com/bensheldon))
|
15
|
+
|
16
|
+
**Closed issues:**
|
17
|
+
|
18
|
+
- Cannot run db:migrate when execution mode is :async [\#229](https://github.com/bensheldon/good_job/issues/229)
|
19
|
+
- How do you enqueue a job to be executed immediately outside of Rails \(eg. creating a new record of good\_jobs in Postgresql\)? [\#225](https://github.com/bensheldon/good_job/issues/225)
|
20
|
+
- Feature Ideas [\#220](https://github.com/bensheldon/good_job/issues/220)
|
21
|
+
- Goodjob startup script for FreeBSD [\#214](https://github.com/bensheldon/good_job/issues/214)
|
22
|
+
- Only start async mode executors when server is running [\#194](https://github.com/bensheldon/good_job/issues/194)
|
23
|
+
|
24
|
+
**Merged pull requests:**
|
25
|
+
|
26
|
+
- Move executable flags from constants to accessors on GoodJob::CLI [\#234](https://github.com/bensheldon/good_job/pull/234) ([bensheldon](https://github.com/bensheldon))
|
27
|
+
- Add custom Scheduler::TimerSet [\#232](https://github.com/bensheldon/good_job/pull/232) ([bensheldon](https://github.com/bensheldon))
|
28
|
+
- Fix assorted constant references in YARD documentation [\#231](https://github.com/bensheldon/good_job/pull/231) ([bensheldon](https://github.com/bensheldon))
|
29
|
+
- Update GH Test Matrix with latest JRuby 9.2.17.0 [\#228](https://github.com/bensheldon/good_job/pull/228) ([tedhexaflow](https://github.com/tedhexaflow))
|
30
|
+
- Update gem dependencies [\#227](https://github.com/bensheldon/good_job/pull/227) ([bensheldon](https://github.com/bensheldon))
|
31
|
+
- Remove leftover text from Readme [\#226](https://github.com/bensheldon/good_job/pull/226) ([weh](https://github.com/weh))
|
32
|
+
- Fix appraisal and bundler version CI conflicts [\#224](https://github.com/bensheldon/good_job/pull/224) ([bensheldon](https://github.com/bensheldon))
|
33
|
+
- Update GH Test Matrix with latest JRuby [\#223](https://github.com/bensheldon/good_job/pull/223) ([tedhexaflow](https://github.com/tedhexaflow))
|
34
|
+
|
35
|
+
## [v1.8.0](https://github.com/bensheldon/good_job/tree/v1.8.0) (2021-03-04)
|
4
36
|
|
5
37
|
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.7.1...v1.8.0)
|
6
38
|
|
@@ -57,7 +89,7 @@
|
|
57
89
|
|
58
90
|
**Closed issues:**
|
59
91
|
|
60
|
-
- Rails 6.1 & async - `
|
92
|
+
- Rails 6.1 & async - `queue_parser': undefined method `first' for "\*":String \(NoMethodError\) [\#195](https://github.com/bensheldon/good_job/issues/195)
|
61
93
|
|
62
94
|
**Merged pull requests:**
|
63
95
|
|
@@ -99,7 +131,6 @@
|
|
99
131
|
**Merged pull requests:**
|
100
132
|
|
101
133
|
- Add missing YARD docs and Dashboard screenshot [\#191](https://github.com/bensheldon/good_job/pull/191) ([bensheldon](https://github.com/bensheldon))
|
102
|
-
- Update all Lockable queries to use exec\_query instead of execute; clear async\_exec results [\#189](https://github.com/bensheldon/good_job/pull/189) ([bensheldon](https://github.com/bensheldon))
|
103
134
|
|
104
135
|
## [v1.4.0](https://github.com/bensheldon/good_job/tree/v1.4.0) (2020-12-31)
|
105
136
|
|
@@ -126,6 +157,7 @@
|
|
126
157
|
**Merged pull requests:**
|
127
158
|
|
128
159
|
- Run tests with Rails default configuration to enable Zeitwerk [\#190](https://github.com/bensheldon/good_job/pull/190) ([bensheldon](https://github.com/bensheldon))
|
160
|
+
- Update all Lockable queries to use exec\_query instead of execute; clear async\_exec results [\#189](https://github.com/bensheldon/good_job/pull/189) ([bensheldon](https://github.com/bensheldon))
|
129
161
|
- Have Lockable\#advisory\_locked? directly query pg\_locks table [\#188](https://github.com/bensheldon/good_job/pull/188) ([bensheldon](https://github.com/bensheldon))
|
130
162
|
- Update development gems, including Rails v6.1 and Rails HEAD [\#186](https://github.com/bensheldon/good_job/pull/186) ([bensheldon](https://github.com/bensheldon))
|
131
163
|
- Update Appraisals for Rails 6.1 [\#183](https://github.com/bensheldon/good_job/pull/183) ([bensheldon](https://github.com/bensheldon))
|
@@ -217,7 +249,7 @@
|
|
217
249
|
**Implemented enhancements:**
|
218
250
|
|
219
251
|
- Preserve only failed jobs [\#136](https://github.com/bensheldon/good_job/issues/136)
|
220
|
-
- Add `GoodJob.
|
252
|
+
- Add `GoodJob.preserve_job_records = :on_unhandled_error` option to only preserve jobs that errored [\#145](https://github.com/bensheldon/good_job/pull/145) ([morgoth](https://github.com/morgoth))
|
221
253
|
|
222
254
|
**Fixed bugs:**
|
223
255
|
|
@@ -250,7 +282,7 @@
|
|
250
282
|
- Update Gemspec to reflect that GoodJob is not compatible with Rails 5.1 [\#143](https://github.com/bensheldon/good_job/pull/143) ([bensheldon](https://github.com/bensheldon))
|
251
283
|
- Prevent jobs hanging [\#141](https://github.com/bensheldon/good_job/pull/141) ([morgoth](https://github.com/morgoth))
|
252
284
|
- Add explicit require\_paths to gemspec for engine [\#134](https://github.com/bensheldon/good_job/pull/134) ([bensheldon](https://github.com/bensheldon))
|
253
|
-
- Use `connection.
|
285
|
+
- Use `connection.quote_table_name` and add spacing for SQL concatenation [\#124](https://github.com/bensheldon/good_job/pull/124) ([bensheldon](https://github.com/bensheldon))
|
254
286
|
|
255
287
|
**Closed issues:**
|
256
288
|
|
@@ -276,7 +308,7 @@
|
|
276
308
|
|
277
309
|
**Implemented enhancements:**
|
278
310
|
|
279
|
-
- Add environment variable to mirror `
|
311
|
+
- Add environment variable to mirror `cleanup_preserved_jobs --before-seconds-ago=SECONDS` [\#110](https://github.com/bensheldon/good_job/issues/110)
|
280
312
|
- Allow env variable config for cleanups [\#114](https://github.com/bensheldon/good_job/pull/114) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
281
313
|
|
282
314
|
**Fixed bugs:**
|
@@ -296,6 +328,7 @@
|
|
296
328
|
- Have YARD render markdown files with GFM \(Github Flavored Markdown\) [\#113](https://github.com/bensheldon/good_job/pull/113) ([bensheldon](https://github.com/bensheldon))
|
297
329
|
- Add markdownlint to lint readme [\#109](https://github.com/bensheldon/good_job/pull/109) ([bensheldon](https://github.com/bensheldon))
|
298
330
|
- Remove unused method in PgLocks [\#107](https://github.com/bensheldon/good_job/pull/107) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
331
|
+
- Re-organize Readme: frontload configuration, add Table of Contents [\#106](https://github.com/bensheldon/good_job/pull/106) ([bensheldon](https://github.com/bensheldon))
|
299
332
|
|
300
333
|
## [v1.2.3](https://github.com/bensheldon/good_job/tree/v1.2.3) (2020-08-27)
|
301
334
|
|
@@ -326,16 +359,15 @@
|
|
326
359
|
|
327
360
|
**Closed issues:**
|
328
361
|
|
329
|
-
- Add test for `rails g
|
362
|
+
- Add test for `rails g good_job:install` [\#57](https://github.com/bensheldon/good_job/issues/57)
|
330
363
|
|
331
364
|
**Merged pull requests:**
|
332
365
|
|
333
|
-
- Re-organize Readme: frontload configuration, add Table of Contents [\#106](https://github.com/bensheldon/good_job/pull/106) ([bensheldon](https://github.com/bensheldon))
|
334
366
|
- Use more ActiveRecord in Lockable and not connection.execute [\#102](https://github.com/bensheldon/good_job/pull/102) ([bensheldon](https://github.com/bensheldon))
|
335
367
|
- Run CI tests on Ruby 2.5, 2.6, and 2.7 [\#101](https://github.com/bensheldon/good_job/pull/101) ([arku](https://github.com/arku))
|
336
368
|
- Fix Ruby 2.7 keyword arguments warning [\#98](https://github.com/bensheldon/good_job/pull/98) ([arku](https://github.com/arku))
|
337
369
|
- Remove executor/reloader for less interlocking [\#97](https://github.com/bensheldon/good_job/pull/97) ([sj26](https://github.com/sj26))
|
338
|
-
- Add test for `rails g
|
370
|
+
- Add test for `rails g good_job:install` [\#94](https://github.com/bensheldon/good_job/pull/94) ([arku](https://github.com/arku))
|
339
371
|
|
340
372
|
## [v1.2.1](https://github.com/bensheldon/good_job/tree/v1.2.1) (2020-08-21)
|
341
373
|
|
@@ -463,7 +495,6 @@
|
|
463
495
|
|
464
496
|
- Add migration generator [\#56](https://github.com/bensheldon/good_job/pull/56) ([thedanbob](https://github.com/thedanbob))
|
465
497
|
- Fix migration script in readme [\#55](https://github.com/bensheldon/good_job/pull/55) ([thedanbob](https://github.com/thedanbob))
|
466
|
-
- Move where\(scheduled\_at: Time.current\) into dynamic part of GoodJob::Job::Performer [\#42](https://github.com/bensheldon/good_job/pull/42) ([bensheldon](https://github.com/bensheldon))
|
467
498
|
|
468
499
|
## [v1.0.1](https://github.com/bensheldon/good_job/tree/v1.0.1) (2020-07-22)
|
469
500
|
|
@@ -502,6 +533,10 @@
|
|
502
533
|
|
503
534
|
[Full Changelog](https://github.com/bensheldon/good_job/compare/v0.8.0...v0.8.1)
|
504
535
|
|
536
|
+
**Merged pull requests:**
|
537
|
+
|
538
|
+
- Move where\(scheduled\_at: Time.current\) into dynamic part of GoodJob::Job::Performer [\#42](https://github.com/bensheldon/good_job/pull/42) ([bensheldon](https://github.com/bensheldon))
|
539
|
+
|
505
540
|
## [v0.8.0](https://github.com/bensheldon/good_job/tree/v0.8.0) (2020-07-17)
|
506
541
|
|
507
542
|
[Full Changelog](https://github.com/bensheldon/good_job/compare/v0.7.0...v0.8.0)
|
@@ -539,7 +574,7 @@
|
|
539
574
|
- Update Github Action Workflow for Backlog Project Board [\#35](https://github.com/bensheldon/good_job/pull/35) ([bensheldon](https://github.com/bensheldon))
|
540
575
|
- Add configuration options to good\_job executable [\#33](https://github.com/bensheldon/good_job/pull/33) ([bensheldon](https://github.com/bensheldon))
|
541
576
|
- Extract Job querying behavior out of Scheduler [\#31](https://github.com/bensheldon/good_job/pull/31) ([bensheldon](https://github.com/bensheldon))
|
542
|
-
- Allow configuration of Rails queue adapter with `:
|
577
|
+
- Allow configuration of Rails queue adapter with `:good_job` [\#28](https://github.com/bensheldon/good_job/pull/28) ([bensheldon](https://github.com/bensheldon))
|
543
578
|
|
544
579
|
## [v0.5.0](https://github.com/bensheldon/good_job/tree/v0.5.0) (2020-07-13)
|
545
580
|
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
|
|
36
36
|
- [`good_job start`](#good_job-start)
|
37
37
|
- [`good_job cleanup_preserved_jobs`](#good_job-cleanup_preserved_jobs)
|
38
38
|
- [Configuration options](#configuration-options)
|
39
|
-
- [Global options](#global-options)
|
39
|
+
- [Global options](#global-options)
|
40
40
|
- [Dashboard](#dashboard)
|
41
41
|
- [Go deeper](#go-deeper)
|
42
42
|
- [Exceptions, retries, and reliability](#exceptions-retries-and-reliability)
|
@@ -119,10 +119,10 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
|
|
119
119
|
- GoodJob can also be configured to execute jobs within the web server process to save on resources. This is useful for low-workloads when economy is paramount.
|
120
120
|
|
121
121
|
```
|
122
|
-
$ GOOD_JOB_EXECUTION_MODE=
|
122
|
+
$ GOOD_JOB_EXECUTION_MODE=async_server rails server
|
123
123
|
```
|
124
124
|
|
125
|
-
Additional configuration is likely necessary, see the reference below for
|
125
|
+
Additional configuration is likely necessary, see the reference below for f configuration.
|
126
126
|
|
127
127
|
## Compatibility
|
128
128
|
|
@@ -206,7 +206,7 @@ Additional configuration can be provided via `config.good_job.OPTION = ...` for
|
|
206
206
|
config.active_job.queue_adapter = :good_job
|
207
207
|
|
208
208
|
# Configure options individually...
|
209
|
-
config.good_job.execution_mode = :
|
209
|
+
config.good_job.execution_mode = :async_server
|
210
210
|
config.good_job.max_threads = 5
|
211
211
|
config.good_job.poll_interval = 30 # seconds
|
212
212
|
config.good_job.shutdown_timeout = 25 # seconds
|
@@ -214,7 +214,7 @@ config.good_job.shutdown_timeout = 25 # seconds
|
|
214
214
|
|
215
215
|
# ...or all at once.
|
216
216
|
config.good_job = {
|
217
|
-
execution_mode: :
|
217
|
+
execution_mode: :async_server,
|
218
218
|
max_threads: 5,
|
219
219
|
poll_interval: 30,
|
220
220
|
shutdown_timeout: 25,
|
@@ -226,10 +226,11 @@ Available configuration options are:
|
|
226
226
|
- `execution_mode` (symbol) specifies how and where jobs should be executed. You can also set this with the environment variable `GOOD_JOB_EXECUTION_MODE`. It can be any one of:
|
227
227
|
- `:inline` executes jobs immediately in whatever process queued them (usually the web server process). This should only be used in test and development environments.
|
228
228
|
- `:external` causes the adapter to enqueue jobs, but not execute them. When using this option (the default for production environments), you’ll need to use the command-line tool to actually execute your jobs.
|
229
|
-
- `:
|
230
|
-
- `
|
231
|
-
- `
|
232
|
-
- `
|
229
|
+
- `:async_server` executes jobs in separate threads within the Rails webserver process (`bundle exec rails server`). It can be more economical for small workloads because you don’t need a separate machine or environment for running your jobs, but if your web server is under heavy load or your jobs require a lot of resources, you should choose `:external` instead. When not in the Rails webserver, jobs will execute in `:external` mode to ensure jobs are not executed within `rails console`, `rails db:migrate`, `rails assets:prepare`, etc.
|
230
|
+
- `:async` executes jobs in separate threads in _any_ Rails process.
|
231
|
+
- `max_threads` (integer) sets the maximum number of threads to use when `execution_mode` is set to `:async` or `:async_server`. You can also set this with the environment variable `GOOD_JOB_MAX_THREADS`.
|
232
|
+
- `queues` (string) determines which queues to execute jobs from when `execution_mode` is set to `:async` or `:async_server`. See the description of `good_job start` for more details on the format of this string. You can also set this with the environment variable `GOOD_JOB_QUEUES`.
|
233
|
+
- `poll_interval` (integer) sets the number of seconds between polls for jobs when `execution_mode` is set to `:async` or `:async_server`. You can also set this with the environment variable `GOOD_JOB_POLL_INTERVAL`.
|
233
234
|
- `max_cache` (integer) sets the maximum number of scheduled jobs that will be stored in memory to reduce execution latency when also polling for scheduled jobs. Caching 10,000 scheduled jobs uses approximately 20MB of memory. You can also set this with the environment variable `GOOD_JOB_MAX_CACHE`.
|
234
235
|
- `shutdown_timeout` (float) number of seconds to wait for jobs to finish when shutting down before stopping the thread. Defaults to forever: `-1`. You can also set this with the environment variable `GOOD_JOB_SHUTDOWN_TIMEOUT`.
|
235
236
|
|
@@ -485,11 +486,11 @@ GoodJob can execute jobs "async" in the same process as the webserver (e.g. `bin
|
|
485
486
|
config.active_job.queue_adapter = :good_job
|
486
487
|
|
487
488
|
# To change the execution mode
|
488
|
-
config.good_job.execution_mode = :
|
489
|
+
config.good_job.execution_mode = :async_server
|
489
490
|
|
490
491
|
# Or with more configuration
|
491
492
|
config.good_job = {
|
492
|
-
execution_mode: :
|
493
|
+
execution_mode: :async_server,
|
493
494
|
max_threads: 4,
|
494
495
|
poll_interval: 30
|
495
496
|
}
|
@@ -498,7 +499,7 @@ GoodJob can execute jobs "async" in the same process as the webserver (e.g. `bin
|
|
498
499
|
- Or, with environment variables:
|
499
500
|
|
500
501
|
```bash
|
501
|
-
$ GOOD_JOB_EXECUTION_MODE=
|
502
|
+
$ GOOD_JOB_EXECUTION_MODE=async_server GOOD_JOB_MAX_THREADS=4 GOOD_JOB_POLL_INTERVAL=30 bin/rails server
|
502
503
|
```
|
503
504
|
|
504
505
|
Depending on your application configuration, you may need to take additional steps:
|
data/exe/good_job
CHANGED
@@ -2,10 +2,6 @@ module ActiveJob # :nodoc:
|
|
2
2
|
module QueueAdapters # :nodoc:
|
3
3
|
# See {GoodJob::Adapter} for details.
|
4
4
|
class GoodJobAdapter < GoodJob::Adapter
|
5
|
-
def initialize(**options)
|
6
|
-
configuration = GoodJob::Configuration.new(options, env: ENV)
|
7
|
-
super(**options.merge(execution_mode: configuration.rails_execution_mode))
|
8
|
-
end
|
9
5
|
end
|
10
6
|
end
|
11
7
|
end
|
data/lib/good_job/adapter.rb
CHANGED
@@ -4,13 +4,15 @@ module GoodJob
|
|
4
4
|
#
|
5
5
|
class Adapter
|
6
6
|
# Valid execution modes.
|
7
|
-
EXECUTION_MODES = [:async, :external, :inline].freeze
|
7
|
+
EXECUTION_MODES = [:async, :async_server, :external, :inline].freeze
|
8
8
|
|
9
9
|
# @param execution_mode [nil, Symbol] specifies how and where jobs should be executed. You can also set this with the environment variable +GOOD_JOB_EXECUTION_MODE+.
|
10
10
|
#
|
11
11
|
# - +:inline+ executes jobs immediately in whatever process queued them (usually the web server process). This should only be used in test and development environments.
|
12
12
|
# - +:external+ causes the adapter to enqueue jobs, but not execute them. When using this option (the default for production environments), you'll need to use the command-line tool to actually execute your jobs.
|
13
|
-
# - +:
|
13
|
+
# - +:async_server+ executes jobs in separate threads within the Rails webserver process (`bundle exec rails server`). It can be more economical for small workloads because you don't need a separate machine or environment for running your jobs, but if your web server is under heavy load or your jobs require a lot of resources, you should choose +:external+ instead.
|
14
|
+
# When not in the Rails webserver, jobs will execute in +:external+ mode to ensure jobs are not executed within `rails console`, `rails db:migrate`, `rails assets:prepare`, etc.
|
15
|
+
# - +:async+ executes jobs in any Rails process.
|
14
16
|
#
|
15
17
|
# The default value depends on the Rails environment:
|
16
18
|
#
|
@@ -46,8 +48,7 @@ module GoodJob
|
|
46
48
|
poll_interval: poll_interval,
|
47
49
|
}
|
48
50
|
)
|
49
|
-
|
50
|
-
raise ArgumentError, "execution_mode: must be one of #{EXECUTION_MODES.join(', ')}." unless EXECUTION_MODES.include?(@configuration.execution_mode)
|
51
|
+
@configuration.validate!
|
51
52
|
|
52
53
|
if execute_async? # rubocop:disable Style/GuardClause
|
53
54
|
@notifier = GoodJob::Notifier.new
|
@@ -126,17 +127,30 @@ module GoodJob
|
|
126
127
|
|
127
128
|
# Whether in +:async+ execution mode.
|
128
129
|
def execute_async?
|
129
|
-
@configuration.execution_mode == :async
|
130
|
+
@configuration.execution_mode == :async ||
|
131
|
+
@configuration.execution_mode == :async_server && in_server_process?
|
130
132
|
end
|
131
133
|
|
132
134
|
# Whether in +:external+ execution mode.
|
133
135
|
def execute_externally?
|
134
|
-
@configuration.execution_mode == :external
|
136
|
+
@configuration.execution_mode == :external ||
|
137
|
+
@configuration.execution_mode == :async_server && !in_server_process?
|
135
138
|
end
|
136
139
|
|
137
140
|
# Whether in +:inline+ execution mode.
|
138
141
|
def execute_inline?
|
139
142
|
@configuration.execution_mode == :inline
|
140
143
|
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
# Whether running in a web server process.
|
148
|
+
def in_server_process?
|
149
|
+
return @_in_server_process if defined? @_in_server_process
|
150
|
+
|
151
|
+
@_in_server_process = Rails.const_defined?('Server') ||
|
152
|
+
caller.grep(%r{config.ru}).any? || # EXAMPLE: config.ru:3:in `block in <main>' OR config.ru:3:in `new_from_string'
|
153
|
+
(Concurrent.on_jruby? && caller.grep(%r{jruby/rack/rails_booter}).any?) # EXAMPLE: uri:classloader:/jruby/rack/rails_booter.rb:83:in `load_environment'
|
154
|
+
end
|
141
155
|
end
|
142
156
|
end
|
data/lib/good_job/cli.rb
CHANGED
@@ -15,9 +15,21 @@ module GoodJob
|
|
15
15
|
# Requiring this loads the application's configuration and classes.
|
16
16
|
RAILS_ENVIRONMENT_RB = File.expand_path("config/environment.rb")
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
class << self
|
19
|
+
# Whether the CLI is running from the executable
|
20
|
+
# @return [Boolean, nil]
|
21
|
+
attr_accessor :within_exe
|
22
|
+
alias within_exe? within_exe
|
23
|
+
|
24
|
+
# Whether to log to STDOUT
|
25
|
+
# @return [Boolean, nil]
|
26
|
+
attr_accessor :log_to_stdout
|
27
|
+
alias log_to_stdout? log_to_stdout
|
28
|
+
|
29
|
+
# @!visibility private
|
30
|
+
def exit_on_failure?
|
31
|
+
true
|
32
|
+
end
|
21
33
|
end
|
22
34
|
|
23
35
|
# @!macro thor.desc
|
@@ -136,7 +148,7 @@ module GoodJob
|
|
136
148
|
# Rails or from the application can be set up here.
|
137
149
|
def set_up_application!
|
138
150
|
require RAILS_ENVIRONMENT_RB
|
139
|
-
return unless
|
151
|
+
return unless GoodJob::CLI.log_to_stdout? && !ActiveSupport::Logger.logger_outputs_to?(GoodJob.logger, $stdout)
|
140
152
|
|
141
153
|
GoodJob::LogSubscriber.loggers << ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new($stdout))
|
142
154
|
GoodJob::LogSubscriber.reset_logger
|
@@ -5,6 +5,8 @@ module GoodJob
|
|
5
5
|
# set options to get the final values for each option.
|
6
6
|
#
|
7
7
|
class Configuration
|
8
|
+
# Valid execution modes.
|
9
|
+
EXECUTION_MODES = [:async, :async_server, :external, :inline].freeze
|
8
10
|
# Default number of threads to use per {Scheduler}
|
9
11
|
DEFAULT_MAX_THREADS = 5
|
10
12
|
# Default number of seconds between polls for jobs
|
@@ -13,7 +15,7 @@ module GoodJob
|
|
13
15
|
DEFAULT_MAX_CACHE = 10000
|
14
16
|
# Default number of seconds to preserve jobs for {CLI#cleanup_preserved_jobs}
|
15
17
|
DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO = 24 * 60 * 60
|
16
|
-
# Default to always wait for jobs to finish for {#shutdown}
|
18
|
+
# Default to always wait for jobs to finish for {Adapter#shutdown}
|
17
19
|
DEFAULT_SHUTDOWN_TIMEOUT = -1
|
18
20
|
|
19
21
|
# The options that were explicitly set when initializing +Configuration+.
|
@@ -35,40 +37,30 @@ module GoodJob
|
|
35
37
|
@env = env
|
36
38
|
end
|
37
39
|
|
40
|
+
def validate!
|
41
|
+
raise ArgumentError, "GoodJob execution mode must be one of #{EXECUTION_MODES.join(', ')}. It was '#{execution_mode}' which is not valid." unless execution_mode.in?(EXECUTION_MODES)
|
42
|
+
end
|
43
|
+
|
38
44
|
# Specifies how and where jobs should be executed. See {Adapter#initialize}
|
39
45
|
# for more details on possible values.
|
40
|
-
#
|
41
|
-
# When running inside a Rails app, you may want to use
|
42
|
-
# {#rails_execution_mode}, which takes the current Rails environment into
|
43
|
-
# account when determining the final value.
|
44
|
-
#
|
45
|
-
# @param default [Symbol]
|
46
|
-
# Value to use if none was specified in the configuration.
|
47
46
|
# @return [Symbol]
|
48
|
-
def execution_mode
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
default
|
59
|
-
end
|
60
|
-
end
|
47
|
+
def execution_mode
|
48
|
+
@_execution_mode ||= begin
|
49
|
+
mode = if GoodJob::CLI.within_exe?
|
50
|
+
:external
|
51
|
+
else
|
52
|
+
options[:execution_mode] ||
|
53
|
+
rails_config[:execution_mode] ||
|
54
|
+
env['GOOD_JOB_EXECUTION_MODE']
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
:inline
|
70
|
-
else
|
71
|
-
:external
|
57
|
+
if mode
|
58
|
+
mode.to_sym
|
59
|
+
elsif Rails.env.development? || Rails.env.test?
|
60
|
+
:inline
|
61
|
+
else
|
62
|
+
:external
|
63
|
+
end
|
72
64
|
end
|
73
65
|
end
|
74
66
|
|
@@ -54,7 +54,7 @@ module GoodJob
|
|
54
54
|
# @param after [DateTime, Time, nil] future jobs scheduled after this time
|
55
55
|
# @param limit [Integer] number of future timestamps to return
|
56
56
|
# @param now_limit [Integer] number of past timestamps to return
|
57
|
-
# @return [Array<(Time,
|
57
|
+
# @return [Array<(Time, DateTime)>, nil]
|
58
58
|
def next_at(after: nil, limit: nil, now_limit: nil)
|
59
59
|
job_query.next_scheduled_at(after: after, limit: limit, now_limit: now_limit)
|
60
60
|
end
|
data/lib/good_job/notifier.rb
CHANGED
@@ -30,7 +30,7 @@ module GoodJob # :nodoc:
|
|
30
30
|
# @!attribute [r] instances
|
31
31
|
# @!scope class
|
32
32
|
# List of all instantiated Notifiers in the current process.
|
33
|
-
# @return [Array<GoodJob
|
33
|
+
# @return [Array<GoodJob::Adapter>]
|
34
34
|
cattr_reader :instances, default: [], instance_reader: false
|
35
35
|
|
36
36
|
# Send a message via Postgres NOTIFY
|
data/lib/good_job/poller.rb
CHANGED
@@ -16,7 +16,7 @@ module GoodJob # :nodoc:
|
|
16
16
|
# @!attribute [r] instances
|
17
17
|
# @!scope class
|
18
18
|
# List of all instantiated Pollers in the current process.
|
19
|
-
# @return [Array<GoodJob
|
19
|
+
# @return [Array<GoodJob::Poller>]
|
20
20
|
cattr_reader :instances, default: [], instance_reader: false
|
21
21
|
|
22
22
|
# Creates GoodJob::Poller from a GoodJob::Configuration instance.
|
@@ -85,7 +85,7 @@ module GoodJob # :nodoc:
|
|
85
85
|
# @return [void]
|
86
86
|
def timer_observer(time, executed_task, thread_error)
|
87
87
|
GoodJob.on_thread_error.call(thread_error) if thread_error && GoodJob.on_thread_error.respond_to?(:call)
|
88
|
-
instrument("finished_timer_task", { result: executed_task, error: thread_error, time: time })
|
88
|
+
ActiveSupport::Notifications.instrument("finished_timer_task", { result: executed_task, error: thread_error, time: time })
|
89
89
|
end
|
90
90
|
|
91
91
|
private
|
data/lib/good_job/scheduler.rb
CHANGED
@@ -30,7 +30,7 @@ module GoodJob # :nodoc:
|
|
30
30
|
# @!attribute [r] instances
|
31
31
|
# @!scope class
|
32
32
|
# List of all instantiated Schedulers in the current process.
|
33
|
-
# @return [Array<GoodJob
|
33
|
+
# @return [Array<GoodJob::Scheduler>]
|
34
34
|
cattr_reader :instances, default: [], instance_reader: false
|
35
35
|
|
36
36
|
# Creates GoodJob::Scheduler(s) and Performers from a GoodJob::Configuration instance.
|
@@ -187,6 +187,8 @@ module GoodJob # :nodoc:
|
|
187
187
|
}
|
188
188
|
end
|
189
189
|
|
190
|
+
# Preload existing runnable and future-scheduled jobs
|
191
|
+
# @return [void]
|
190
192
|
def warm_cache
|
191
193
|
return if @max_cache.zero?
|
192
194
|
|
@@ -204,7 +206,7 @@ module GoodJob # :nodoc:
|
|
204
206
|
|
205
207
|
def create_executor
|
206
208
|
instrument("scheduler_create_pool", { performer_name: performer.name, max_threads: @executor_options[:max_threads] }) do
|
207
|
-
@timer_set =
|
209
|
+
@timer_set = TimerSet.new
|
208
210
|
@executor = ThreadPoolExecutor.new(@executor_options)
|
209
211
|
end
|
210
212
|
end
|
@@ -230,7 +232,7 @@ module GoodJob # :nodoc:
|
|
230
232
|
end
|
231
233
|
|
232
234
|
def cache_count
|
233
|
-
timer_set.
|
235
|
+
timer_set.length
|
234
236
|
end
|
235
237
|
|
236
238
|
def remaining_cache_count
|
@@ -255,5 +257,21 @@ module GoodJob # :nodoc:
|
|
255
257
|
end
|
256
258
|
end
|
257
259
|
end
|
260
|
+
|
261
|
+
# Custom sub-class of +Concurrent::TimerSet+ for additional behavior.
|
262
|
+
# @private
|
263
|
+
class TimerSet < Concurrent::TimerSet
|
264
|
+
# Number of scheduled jobs in the queue
|
265
|
+
# @return [Integer]
|
266
|
+
def length
|
267
|
+
@queue.length
|
268
|
+
end
|
269
|
+
|
270
|
+
# Clear the queue
|
271
|
+
# @return [void]
|
272
|
+
def reset
|
273
|
+
synchronize { @queue.clear }
|
274
|
+
end
|
275
|
+
end
|
258
276
|
end
|
259
277
|
end
|
data/lib/good_job/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Sheldon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '2.0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: appraisal
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: capybara
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -400,7 +386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
400
386
|
- !ruby/object:Gem::Version
|
401
387
|
version: '0'
|
402
388
|
requirements: []
|
403
|
-
rubygems_version: 3.
|
389
|
+
rubygems_version: 3.2.13
|
404
390
|
signing_key:
|
405
391
|
specification_version: 4
|
406
392
|
summary: A multithreaded, Postgres-based ActiveJob backend for Ruby on Rails
|