good_job 1.11.1 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +76 -5
- data/README.md +93 -4
- data/engine/app/controllers/good_job/active_jobs_controller.rb +1 -0
- data/engine/app/controllers/good_job/assets_controller.rb +1 -0
- data/engine/app/controllers/good_job/base_controller.rb +1 -0
- data/engine/app/controllers/good_job/dashboards_controller.rb +1 -0
- data/engine/app/controllers/good_job/jobs_controller.rb +1 -0
- data/engine/app/helpers/good_job/application_helper.rb +1 -0
- data/engine/app/views/good_job/active_jobs/show.html.erb +1 -1
- data/engine/app/views/good_job/dashboards/index.html.erb +2 -2
- data/engine/app/views/{shared → good_job/shared}/_chart.erb +2 -2
- data/engine/app/views/{shared → good_job/shared}/_jobs_table.erb +1 -1
- data/engine/app/views/{shared → good_job/shared}/icons/_check.html.erb +0 -0
- data/engine/app/views/{shared → good_job/shared}/icons/_exclamation.html.erb +0 -0
- data/engine/app/views/{shared → good_job/shared}/icons/_trash.html.erb +0 -0
- data/engine/app/views/layouts/good_job/base.html.erb +7 -7
- data/engine/config/routes.rb +11 -5
- data/engine/lib/good_job/engine.rb +1 -0
- data/exe/good_job +1 -0
- data/lib/active_job/queue_adapters/good_job_adapter.rb +1 -0
- data/lib/generators/good_job/install_generator.rb +1 -0
- data/lib/generators/good_job/templates/update/migrations/01_create_good_jobs.rb +1 -0
- data/lib/generators/good_job/templates/update/migrations/02_add_active_job_id_concurrency_key_cron_key_to_good_jobs.rb +1 -0
- data/lib/generators/good_job/templates/update/migrations/03_add_active_job_id_index_and_concurrency_key_index_to_good_jobs.rb +1 -0
- data/lib/generators/good_job/update_generator.rb +1 -0
- data/lib/good_job.rb +16 -10
- data/lib/good_job/active_job_extensions.rb +1 -0
- data/lib/good_job/active_job_extensions/concurrency.rb +1 -0
- data/lib/good_job/adapter.rb +3 -0
- data/lib/good_job/cli.rb +8 -2
- data/lib/good_job/configuration.rb +25 -0
- data/lib/good_job/cron_manager.rb +115 -0
- data/lib/good_job/current_execution.rb +7 -0
- data/lib/good_job/daemon.rb +1 -0
- data/lib/good_job/execution_result.rb +1 -0
- data/lib/good_job/job.rb +25 -2
- data/lib/good_job/job_performer.rb +1 -0
- data/lib/good_job/lockable.rb +1 -0
- data/lib/good_job/log_subscriber.rb +11 -0
- data/lib/good_job/multi_scheduler.rb +1 -0
- data/lib/good_job/notifier.rb +13 -4
- data/lib/good_job/poller.rb +1 -0
- data/lib/good_job/railtie.rb +3 -0
- data/lib/good_job/scheduler.rb +1 -0
- data/lib/good_job/version.rb +2 -1
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b4629010561604c4f1d77812c3ca7301e5600fa8e0637fd584a769898d43aa5
|
4
|
+
data.tar.gz: 1216b9d590c40c047fa25c13afec94021891752bab8ec36ff7f6c968af8e285e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef51328facf01deeec6a2e67c38c526c944d1c7381fa45cf97f7f05aa4897ac711c324f616e8d948c3c5e6e4e5fae636ea2c7c3c9d48d79de0ead78ed438580f
|
7
|
+
data.tar.gz: e4efa15858ac7a6c0849ec084a00de8fbb8f6751523e78c9234b118bee2c84f3709c549cfc1f161af5166b2d54ff1f358b2dbd18e54adca06d6c62ad10757827
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,85 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [v1.
|
3
|
+
## [v1.12.1](https://github.com/bensheldon/good_job/tree/v1.12.1) (2021-08-05)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.
|
5
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.12.0...v1.12.1)
|
6
|
+
|
7
|
+
**Fixed bugs:**
|
8
|
+
|
9
|
+
- Ensure CLI can shutdown cleanly with multiple queues and timeout [\#319](https://github.com/bensheldon/good_job/pull/319) ([bensheldon](https://github.com/bensheldon))
|
6
10
|
|
7
11
|
**Closed issues:**
|
8
12
|
|
9
|
-
-
|
13
|
+
- Setting a shutdown timeout causes the CLI executor to throw an exception on shutdown. [\#318](https://github.com/bensheldon/good_job/issues/318)
|
14
|
+
- PgBouncer and prepared statements [\#269](https://github.com/bensheldon/good_job/issues/269)
|
15
|
+
- Question about locking internals [\#212](https://github.com/bensheldon/good_job/issues/212)
|
16
|
+
- Encoding::UndefinedConversionError \("\xE2" from ASCII-8BIT to UTF-8\) [\#198](https://github.com/bensheldon/good_job/issues/198)
|
17
|
+
- tools for managing a 'fleet' of processes [\#150](https://github.com/bensheldon/good_job/issues/150)
|
18
|
+
|
19
|
+
**Merged pull requests:**
|
20
|
+
|
21
|
+
- Fix Readme lint warnings [\#320](https://github.com/bensheldon/good_job/pull/320) ([bensheldon](https://github.com/bensheldon))
|
22
|
+
|
23
|
+
## [v1.12.0](https://github.com/bensheldon/good_job/tree/v1.12.0) (2021-07-27)
|
24
|
+
|
25
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.3...v1.12.0)
|
26
|
+
|
27
|
+
**Implemented enhancements:**
|
28
|
+
|
29
|
+
- Add the ability to schedule repeating / recurring / cron-like jobs [\#53](https://github.com/bensheldon/good_job/issues/53)
|
30
|
+
- Add cron-like support for recurring/repeating jobs [\#297](https://github.com/bensheldon/good_job/pull/297) ([bensheldon](https://github.com/bensheldon))
|
10
31
|
|
11
32
|
**Merged pull requests:**
|
12
33
|
|
34
|
+
- Place Dashboard shared view partials under `good_job` namespace [\#310](https://github.com/bensheldon/good_job/pull/310) ([bensheldon](https://github.com/bensheldon))
|
35
|
+
- Ensure Dashboard inline javascript has CSP nonce for strict Content-Security Policy [\#309](https://github.com/bensheldon/good_job/pull/309) ([bensheldon](https://github.com/bensheldon))
|
36
|
+
|
37
|
+
## [v1.11.3](https://github.com/bensheldon/good_job/tree/v1.11.3) (2021-07-25)
|
38
|
+
|
39
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.2...v1.11.3)
|
40
|
+
|
41
|
+
**Closed issues:**
|
42
|
+
|
43
|
+
- ERROR: relation "good\_jobs" does not exist at character 454 [\#308](https://github.com/bensheldon/good_job/issues/308)
|
44
|
+
- Add Frozen String Literal to all files [\#298](https://github.com/bensheldon/good_job/issues/298)
|
45
|
+
- Support for good\_job without Rails? [\#295](https://github.com/bensheldon/good_job/issues/295)
|
46
|
+
|
47
|
+
**Merged pull requests:**
|
48
|
+
|
49
|
+
- Have prettier Dashboard asset urls e.g. `bootstrap.css` instead of `bootstrap_css.css` [\#306](https://github.com/bensheldon/good_job/pull/306) ([bensheldon](https://github.com/bensheldon))
|
50
|
+
- Create dashboard demo app on Heroku [\#305](https://github.com/bensheldon/good_job/pull/305) ([bensheldon](https://github.com/bensheldon))
|
51
|
+
- Add Frozen String Literal to all files [\#302](https://github.com/bensheldon/good_job/pull/302) ([tedhexaflow](https://github.com/tedhexaflow))
|
52
|
+
|
53
|
+
## [v1.11.2](https://github.com/bensheldon/good_job/tree/v1.11.2) (2021-07-20)
|
54
|
+
|
55
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.1...v1.11.2)
|
56
|
+
|
57
|
+
**Fixed bugs:**
|
58
|
+
|
59
|
+
- Notifier waits to retry listening when database is unavailable [\#301](https://github.com/bensheldon/good_job/pull/301) ([bensheldon](https://github.com/bensheldon))
|
60
|
+
|
61
|
+
**Closed issues:**
|
62
|
+
|
63
|
+
- Handle database connection drops [\#296](https://github.com/bensheldon/good_job/issues/296)
|
64
|
+
- Using the `async` worker results in `ActiveModel::UnknownAttributeError unknown attribute 'create_with_advisory_lock' for GoodJob::Job`. [\#290](https://github.com/bensheldon/good_job/issues/290)
|
65
|
+
|
66
|
+
**Merged pull requests:**
|
67
|
+
|
68
|
+
- Rename development and test databases to be `good_job` [\#300](https://github.com/bensheldon/good_job/pull/300) ([bensheldon](https://github.com/bensheldon))
|
69
|
+
- Move generators spec into top-level spec directory; update dependencies [\#299](https://github.com/bensheldon/good_job/pull/299) ([bensheldon](https://github.com/bensheldon))
|
70
|
+
|
71
|
+
## [v1.11.1](https://github.com/bensheldon/good_job/tree/v1.11.1) (2021-07-07)
|
72
|
+
|
73
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.0...v1.11.1)
|
74
|
+
|
75
|
+
**Fixed bugs:**
|
76
|
+
|
13
77
|
- Defer accessing ActiveRecord `primary_key` in Lockable [\#293](https://github.com/bensheldon/good_job/pull/293) ([bensheldon](https://github.com/bensheldon))
|
14
78
|
|
79
|
+
**Closed issues:**
|
80
|
+
|
81
|
+
- Database connection required while loading the code on 1.10.x [\#291](https://github.com/bensheldon/good_job/issues/291)
|
82
|
+
|
15
83
|
## [v1.11.0](https://github.com/bensheldon/good_job/tree/v1.11.0) (2021-07-07)
|
16
84
|
|
17
85
|
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.10.1...v1.11.0)
|
@@ -32,9 +100,12 @@
|
|
32
100
|
|
33
101
|
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.10.0...v1.10.1)
|
34
102
|
|
35
|
-
**
|
103
|
+
**Fixed bugs:**
|
36
104
|
|
37
105
|
- Remove `FOR UPDATE SKIP LOCKED` from job locking sql statement [\#288](https://github.com/bensheldon/good_job/pull/288) ([bensheldon](https://github.com/bensheldon))
|
106
|
+
|
107
|
+
**Merged pull requests:**
|
108
|
+
|
38
109
|
- Update GH Test Matrix with latest JRuby 9.2.19.0 [\#283](https://github.com/bensheldon/good_job/pull/283) ([tedhexaflow](https://github.com/tedhexaflow))
|
39
110
|
|
40
111
|
## [v1.10.0](https://github.com/bensheldon/good_job/tree/v1.10.0) (2021-06-29)
|
@@ -43,11 +114,11 @@
|
|
43
114
|
|
44
115
|
**Implemented enhancements:**
|
45
116
|
|
117
|
+
- Use `pg_advisory_unlock_all` after each thread's job execution; fix Lockable return values; improve test stability [\#285](https://github.com/bensheldon/good_job/pull/285) ([bensheldon](https://github.com/bensheldon))
|
46
118
|
- Add `rails g good_job:update` command to add idempotent migration files, including `active_job_id`, `concurrency_key`, `cron_key` columns [\#266](https://github.com/bensheldon/good_job/pull/266) ([bensheldon](https://github.com/bensheldon))
|
47
119
|
|
48
120
|
**Fixed bugs:**
|
49
121
|
|
50
|
-
- Use `pg_advisory_unlock_all` after each thread's job execution; fix Lockable return values; improve test stability [\#285](https://github.com/bensheldon/good_job/pull/285) ([bensheldon](https://github.com/bensheldon))
|
51
122
|
- Dashboard AssetsController does not raise if verify\_authenticity\_token is not in the callback chain [\#284](https://github.com/bensheldon/good_job/pull/284) ([bensheldon](https://github.com/bensheldon))
|
52
123
|
|
53
124
|
**Closed issues:**
|
data/README.md
CHANGED
@@ -38,7 +38,8 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
|
|
38
38
|
- [Configuration options](#configuration-options)
|
39
39
|
- [Global options](#global-options)
|
40
40
|
- [Dashboard](#dashboard)
|
41
|
-
- [ActiveJob
|
41
|
+
- [ActiveJob concurrency](#activejob-concurrency)
|
42
|
+
- [Cron-style repeating/recurring jobs](#cron-style-repeatingrecurring-jobs)
|
42
43
|
- [Updating](#updating)
|
43
44
|
- [Go deeper](#go-deeper)
|
44
45
|
- [Exceptions, retries, and reliability](#exceptions-retries-and-reliability)
|
@@ -51,6 +52,7 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
|
|
51
52
|
- [Execute jobs async / in-process](#execute-jobs-async--in-process)
|
52
53
|
- [Migrate to GoodJob from a different ActiveJob backend](#migrate-to-goodjob-from-a-different-activejob-backend)
|
53
54
|
- [Monitor and preserve worked jobs](#monitor-and-preserve-worked-jobs)
|
55
|
+
- [PgBouncer compatibility](#pgbouncer-compatibility)
|
54
56
|
- [Contribute](#contribute)
|
55
57
|
- [Gem development](#gem-development)
|
56
58
|
- [Release](#release)
|
@@ -156,6 +158,7 @@ Options:
|
|
156
158
|
[--poll-interval=SECONDS] # Interval between polls for available jobs in seconds (env var: GOOD_JOB_POLL_INTERVAL, default: 1)
|
157
159
|
[--max-cache=COUNT] # Maximum number of scheduled jobs to cache in memory (env var: GOOD_JOB_MAX_CACHE, default: 10000)
|
158
160
|
[--shutdown-timeout=SECONDS] # Number of seconds to wait for jobs to finish when shutting down before stopping the thread. (env var: GOOD_JOB_SHUTDOWN_TIMEOUT, default: -1 (forever))
|
161
|
+
[--enable-cron] # Whether to run cron process (default: false)
|
159
162
|
[--daemonize] # Run as a background daemon (default: false)
|
160
163
|
[--pidfile=PIDFILE] # Path to write daemonized Process ID (env var: GOOD_JOB_PIDFILE, default: tmp/pids/good_job.pid)
|
161
164
|
|
@@ -212,7 +215,8 @@ config.good_job.execution_mode = :async_server
|
|
212
215
|
config.good_job.max_threads = 5
|
213
216
|
config.good_job.poll_interval = 30 # seconds
|
214
217
|
config.good_job.shutdown_timeout = 25 # seconds
|
215
|
-
|
218
|
+
config.good_job.enable_cron = true
|
219
|
+
config.good_job.cron = { example: { cron: '0 * * * *', class: 'ExampleJob' } }
|
216
220
|
|
217
221
|
# ...or all at once.
|
218
222
|
config.good_job = {
|
@@ -220,6 +224,13 @@ config.good_job = {
|
|
220
224
|
max_threads: 5,
|
221
225
|
poll_interval: 30,
|
222
226
|
shutdown_timeout: 25,
|
227
|
+
enable_cron: true,
|
228
|
+
cron: {
|
229
|
+
example: {
|
230
|
+
cron: '0 * * * *',
|
231
|
+
class: 'ExampleJob'
|
232
|
+
},
|
233
|
+
},
|
223
234
|
}
|
224
235
|
```
|
225
236
|
|
@@ -235,6 +246,8 @@ Available configuration options are:
|
|
235
246
|
- `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`.
|
236
247
|
- `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`.
|
237
248
|
- `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`.
|
249
|
+
- `enable_cron` (boolean) whether to run cron process. Defaults to `false`. You can also set this with the environment variable `GOOD_JOB_ENABLE_CRON`.
|
250
|
+
- `cron` (hash) cron configuration. Defaults to `{}`. You can also set this as a JSON string with the environment variable `GOOD_JOB_CRON`
|
238
251
|
|
239
252
|
By default, GoodJob configures the following execution modes per environment:
|
240
253
|
|
@@ -320,9 +333,9 @@ GoodJob includes a Dashboard as a mountable `Rails::Engine`.
|
|
320
333
|
end
|
321
334
|
```
|
322
335
|
|
323
|
-
### ActiveJob
|
336
|
+
### ActiveJob concurrency
|
324
337
|
|
325
|
-
GoodJob can extend ActiveJob to provide limits on concurrently running jobs, either at time of _enqueue_ or at _perform_.
|
338
|
+
GoodJob can extend ActiveJob to provide limits on concurrently running jobs, either at time of _enqueue_ or at _perform_. Limiting concurrency can help prevent duplicate, double or unecessary jobs from being enqueued, or race conditions when performing, for example when interacting with 3rd-party APIs.
|
326
339
|
|
327
340
|
**Note:** Limiting concurrency at _enqueue_ requires Rails 6.0+ because Rails 5.2 does not support `throw :abort` in ActiveJob callbacks.
|
328
341
|
|
@@ -349,6 +362,45 @@ class MyJob < ApplicationJob
|
|
349
362
|
end
|
350
363
|
```
|
351
364
|
|
365
|
+
When testing, the resulting concurrency key value can be inspected:
|
366
|
+
|
367
|
+
```ruby
|
368
|
+
job = MyJob.perform_later("Alice")
|
369
|
+
job.good_job_concurrency_key #=> "Unique-Alice"
|
370
|
+
```
|
371
|
+
|
372
|
+
### Cron-style repeating/recurring jobs
|
373
|
+
|
374
|
+
GoodJob can enqueue jobs on a recurring basis that can be used as a replacement for cron.
|
375
|
+
|
376
|
+
Cron-style jobs are run on every GoodJob process (e.g. CLI or `async` execution mode) when `config.good_job.enable_cron = true`; use GoodJob's [ActiveJob concurrency](#activejob-concurrency) extension to limit the number of jobs that are enqueued.
|
377
|
+
|
378
|
+
Cron-format is parsed by the [`fugit`](https://github.com/floraison/fugit) gem, which has support for seconds-level resolution (e.g. `* * * * * *`).
|
379
|
+
|
380
|
+
```ruby
|
381
|
+
# config/environments/application.rb or a specific environment e.g. production.rb
|
382
|
+
|
383
|
+
# Enable cron in this process; e.g. only run on the first Heroku worker process
|
384
|
+
config.good_job.enable_cron = ENV['DYNO'] == 'worker.1' # or `true` or via $GOOD_JOB_ENABLE_CRON
|
385
|
+
|
386
|
+
# Configure cron with a hash that has a unique key for each recurring job
|
387
|
+
config.good_job.cron = {
|
388
|
+
# Every 15 minutes, enqueue `ExampleJob.set(priority: -10).perform_later(52, name: "Alice")`
|
389
|
+
frequent_task: { # each recurring job must have a unique key
|
390
|
+
cron: "*/15 * * * *", # cron-style scheduling format by fugit gem
|
391
|
+
class: "ExampleJob", # reference the Job class with a string
|
392
|
+
args: [42, { name: "Alice" }], # arguments to pass; can also be a proc e.g. `-> { { when: Time.now } }`
|
393
|
+
set: { priority: -10 }, # additional ActiveJob properties; can also be a lambda/proc e.g. `-> { { priority: [1,2].sample } }`
|
394
|
+
description: "Something helpful", # optional description that appears in Dashboard (coming soon!)
|
395
|
+
},
|
396
|
+
another_task: {
|
397
|
+
cron: "0 0,12 * * *",
|
398
|
+
class: "AnotherJob",
|
399
|
+
},
|
400
|
+
# etc.
|
401
|
+
}
|
402
|
+
```
|
403
|
+
|
352
404
|
### Updating
|
353
405
|
|
354
406
|
GoodJob follows semantic versioning, though updates may be encouraged through deprecation warnings in minor versions.
|
@@ -636,6 +688,43 @@ It is also necessary to delete these preserved jobs from the database after a ce
|
|
636
688
|
$ bundle exec good_job cleanup_preserved_jobs --before-seconds-ago=86400
|
637
689
|
```
|
638
690
|
|
691
|
+
### PgBouncer compatibility
|
692
|
+
|
693
|
+
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.
|
694
|
+
|
695
|
+
A workaround to this limitation is to make a direct database connection available to GoodJob. With Rails 6.0's support for [multiple databases](https://guides.rubyonrails.org/active_record_multiple_databases.html), a direct connection to the database can be configured:
|
696
|
+
|
697
|
+
1. Define a direct connection to your database that is not proxied through PgBouncer, for example:
|
698
|
+
|
699
|
+
```yml
|
700
|
+
# config/database.yml
|
701
|
+
|
702
|
+
production:
|
703
|
+
primary:
|
704
|
+
url: postgres://pgbouncer_host/my_database
|
705
|
+
primary_direct:
|
706
|
+
url: postgres://database_host/my_database
|
707
|
+
```
|
708
|
+
|
709
|
+
1. Create a new ActiveRecord base class that uses the direct database connection
|
710
|
+
|
711
|
+
```ruby
|
712
|
+
# app/models/application_direct_record.rb
|
713
|
+
|
714
|
+
class ApplicationDirectRecord < ActiveRecord::Base
|
715
|
+
self.abstract_class = true
|
716
|
+
connects_to database: :primary_direct
|
717
|
+
end
|
718
|
+
```
|
719
|
+
|
720
|
+
1. Configure GoodJob to use the newly created ActiveRecord base class:
|
721
|
+
|
722
|
+
```ruby
|
723
|
+
# config/initializers/good_job.rb
|
724
|
+
|
725
|
+
GoodJob.active_record_parent_class = "ApplicationDirectRecord"
|
726
|
+
```
|
727
|
+
|
639
728
|
## Contribute
|
640
729
|
|
641
730
|
Contributions are welcomed and appreciated 🙏
|
@@ -1 +1 @@
|
|
1
|
-
<%= render 'shared/jobs_table', jobs: @jobs %>
|
1
|
+
<%= render 'good_job/shared/jobs_table', jobs: @jobs %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<div class="card my-3 p-6">
|
2
|
-
<%= render 'shared/chart', chart_data: @chart %>
|
2
|
+
<%= render 'good_job/shared/chart', chart_data: @chart %>
|
3
3
|
</div>
|
4
4
|
|
5
5
|
<div class='card mb-2'>
|
@@ -38,7 +38,7 @@
|
|
38
38
|
</div>
|
39
39
|
|
40
40
|
<% if @filter.jobs.present? %>
|
41
|
-
<%= render 'shared/jobs_table', jobs: @filter.jobs %>
|
41
|
+
<%= render 'good_job/shared/jobs_table', jobs: @filter.jobs %>
|
42
42
|
|
43
43
|
<nav aria-label="Job pagination" class="mt-3">
|
44
44
|
<ul class="pagination">
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<div id="chart"></div>
|
2
2
|
|
3
|
-
|
3
|
+
<%= javascript_tag nonce: true do %>
|
4
4
|
new Chartist.Line('#chart', <%== chart_data.to_json %>, {
|
5
5
|
height: '300px',
|
6
6
|
fullWidth: true,
|
@@ -49,4 +49,4 @@
|
|
49
49
|
tooltipEl.style.left = (event.offsetX || event.originalEvent.layerX) + tooltipEl.offsetWidth + 10 + 'px';
|
50
50
|
tooltipEl.style.top = (event.offsetY || event.originalEvent.layerY) + tooltipEl.offsetHeight - 20 + 'px';
|
51
51
|
}, true);
|
52
|
-
|
52
|
+
<% end %>
|
File without changes
|
File without changes
|
File without changes
|
@@ -5,12 +5,12 @@
|
|
5
5
|
<%= csrf_meta_tags %>
|
6
6
|
<%= csp_meta_tag %>
|
7
7
|
|
8
|
-
<%= stylesheet_link_tag
|
9
|
-
<%= stylesheet_link_tag
|
10
|
-
<%= stylesheet_link_tag
|
8
|
+
<%= stylesheet_link_tag bootstrap_path(format: :css, v: GoodJob::VERSION) %>
|
9
|
+
<%= stylesheet_link_tag chartist_path(format: :css, v: GoodJob::VERSION) %>
|
10
|
+
<%= stylesheet_link_tag style_path(format: :css, v: GoodJob::VERSION) %>
|
11
11
|
|
12
|
-
<%= javascript_include_tag
|
13
|
-
<%= javascript_include_tag
|
12
|
+
<%= javascript_include_tag bootstrap_path(format: :js, v: GoodJob::VERSION) %>
|
13
|
+
<%= javascript_include_tag chartist_path(format: :js, v: GoodJob::VERSION) %>
|
14
14
|
</head>
|
15
15
|
<body>
|
16
16
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
@@ -53,13 +53,13 @@
|
|
53
53
|
|
54
54
|
<% if notice %>
|
55
55
|
<div class="alert alert-success alert-dismissible fade show d-flex align-items-center offset-md-3 col-6" role="alert">
|
56
|
-
<%= render "shared/icons/check", class: "flex-shrink-0 me-2" %>
|
56
|
+
<%= render "good_job/shared/icons/check", class: "flex-shrink-0 me-2" %>
|
57
57
|
<div><%= notice %></div>
|
58
58
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
59
59
|
</div>
|
60
60
|
<% elsif alert %>
|
61
61
|
<div class="alert alert-warning alert-dismissible fade show d-flex align-items-center offset-md-3 col-6" role="alert">
|
62
|
-
<%= render "shared/icons/check", class: "flex-shrink-0 me-2" %>
|
62
|
+
<%= render "good_job/shared/icons/check", class: "flex-shrink-0 me-2" %>
|
63
63
|
<div><%= alert %></div>
|
64
64
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
65
65
|
</div>
|
data/engine/config/routes.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
GoodJob::Engine.routes.draw do
|
2
3
|
root to: 'dashboards#index'
|
3
4
|
resources :active_jobs, only: %i[show]
|
4
5
|
resources :jobs, only: %i[destroy]
|
5
6
|
|
6
7
|
scope controller: :assets do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
constraints(format: :css) do
|
9
|
+
get :bootstrap, action: :bootstrap_css
|
10
|
+
get :chartist, action: :chartist_css
|
11
|
+
get :style, action: :style_css
|
12
|
+
end
|
13
|
+
|
14
|
+
constraints(format: :js) do
|
15
|
+
get :bootstrap, action: :bootstrap_js
|
16
|
+
get :chartist, action: :chartist_js
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
data/exe/good_job
CHANGED
data/lib/good_job.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "rails"
|
2
3
|
require "active_job"
|
3
4
|
require "active_job/queue_adapters"
|
@@ -105,16 +106,13 @@ module GoodJob
|
|
105
106
|
wait ? -1 : nil
|
106
107
|
end
|
107
108
|
|
108
|
-
|
109
|
-
_shutdown_all(executables, timeout: timeout)
|
109
|
+
_shutdown_all(_executables, timeout: timeout)
|
110
110
|
end
|
111
111
|
|
112
112
|
# Tests whether jobs have stopped executing.
|
113
113
|
# @return [Boolean] whether background threads are shut down
|
114
114
|
def self.shutdown?
|
115
|
-
|
116
|
-
Poller.instances.all?(&:shutdown?) &&
|
117
|
-
Scheduler.instances.all?(&:shutdown?)
|
115
|
+
_executables.all?(&:shutdown?)
|
118
116
|
end
|
119
117
|
|
120
118
|
# Stops and restarts executing jobs.
|
@@ -125,17 +123,16 @@ module GoodJob
|
|
125
123
|
# @param timeout [Numeric, nil] Seconds to wait for active threads to finish.
|
126
124
|
# @return [void]
|
127
125
|
def self.restart(timeout: -1)
|
128
|
-
|
129
|
-
_shutdown_all(executables, :restart, timeout: timeout)
|
126
|
+
_shutdown_all(_executables, :restart, timeout: timeout)
|
130
127
|
end
|
131
128
|
|
132
|
-
# Sends +#shutdown+ or +#restart+ to executable objects ({GoodJob::Notifier}, {GoodJob::Poller}, {GoodJob::Scheduler})
|
133
|
-
# @param executables [Array<Notifier, Poller, Scheduler, MultiScheduler>] Objects to shut down.
|
129
|
+
# Sends +#shutdown+ or +#restart+ to executable objects ({GoodJob::Notifier}, {GoodJob::Poller}, {GoodJob::Scheduler}, {GoodJob::MultiScheduler}, {GoodJob::CronManager})
|
130
|
+
# @param executables [Array<Notifier, Poller, Scheduler, MultiScheduler, CronManager>] Objects to shut down.
|
134
131
|
# @param method_name [:symbol] Method to call, e.g. +:shutdown+ or +:restart+.
|
135
132
|
# @param timeout [nil,Numeric]
|
136
133
|
# @return [void]
|
137
134
|
def self._shutdown_all(executables, method_name = :shutdown, timeout: -1)
|
138
|
-
if timeout.positive?
|
135
|
+
if timeout.is_a?(Numeric) && timeout.positive?
|
139
136
|
executables.each { |executable| executable.send(method_name, timeout: nil) }
|
140
137
|
|
141
138
|
stop_at = Time.current + timeout
|
@@ -145,5 +142,14 @@ module GoodJob
|
|
145
142
|
end
|
146
143
|
end
|
147
144
|
|
145
|
+
def self._executables
|
146
|
+
[].concat(
|
147
|
+
CronManager.instances,
|
148
|
+
Notifier.instances,
|
149
|
+
Poller.instances,
|
150
|
+
Scheduler.instances
|
151
|
+
)
|
152
|
+
end
|
153
|
+
|
148
154
|
ActiveSupport.run_load_hooks(:good_job, self)
|
149
155
|
end
|
data/lib/good_job/adapter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GoodJob
|
2
3
|
#
|
3
4
|
# ActiveJob Adapter.
|
@@ -56,6 +57,8 @@ module GoodJob
|
|
56
57
|
@scheduler = GoodJob::Scheduler.from_configuration(@configuration, warm_cache_on_initialize: Rails.application.initialized?)
|
57
58
|
@notifier.recipients << [@scheduler, :create_thread]
|
58
59
|
@poller.recipients << [@scheduler, :create_thread]
|
60
|
+
|
61
|
+
@cron_manager = GoodJob::CronManager.new(@configuration.cron, start_on_initialize: Rails.application.initialized?) if @configuration.enable_cron?
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
data/lib/good_job/cli.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'thor'
|
2
3
|
|
3
4
|
module GoodJob
|
@@ -69,12 +70,16 @@ module GoodJob
|
|
69
70
|
type: :numeric,
|
70
71
|
banner: 'SECONDS',
|
71
72
|
desc: "Number of seconds to wait for jobs to finish when shutting down before stopping the thread. (env var: GOOD_JOB_SHUTDOWN_TIMEOUT, default: -1 (forever))"
|
73
|
+
method_option :enable_cron,
|
74
|
+
type: :boolean,
|
75
|
+
desc: "Whether to run cron process (default: false)"
|
72
76
|
method_option :daemonize,
|
73
77
|
type: :boolean,
|
74
78
|
desc: "Run as a background daemon (default: false)"
|
75
79
|
method_option :pidfile,
|
76
80
|
type: :string,
|
77
81
|
desc: "Path to write daemonized Process ID (env var: GOOD_JOB_PIDFILE, default: tmp/pids/good_job.pid)"
|
82
|
+
|
78
83
|
def start
|
79
84
|
set_up_application!
|
80
85
|
configuration = GoodJob::Configuration.new(options)
|
@@ -86,7 +91,7 @@ module GoodJob
|
|
86
91
|
scheduler = GoodJob::Scheduler.from_configuration(configuration, warm_cache_on_initialize: true)
|
87
92
|
notifier.recipients << [scheduler, :create_thread]
|
88
93
|
poller.recipients << [scheduler, :create_thread]
|
89
|
-
|
94
|
+
cron_manager = GoodJob::CronManager.new(configuration.cron, start_on_initialize: true) if configuration.enable_cron?
|
90
95
|
@stop_good_job_executable = false
|
91
96
|
%w[INT TERM].each do |signal|
|
92
97
|
trap(signal) { @stop_good_job_executable = true }
|
@@ -97,7 +102,7 @@ module GoodJob
|
|
97
102
|
break if @stop_good_job_executable || scheduler.shutdown? || notifier.shutdown?
|
98
103
|
end
|
99
104
|
|
100
|
-
executors = [notifier, poller, scheduler]
|
105
|
+
executors = [notifier, poller, cron_manager, scheduler].compact
|
101
106
|
GoodJob._shutdown_all(executors, timeout: configuration.shutdown_timeout)
|
102
107
|
end
|
103
108
|
|
@@ -123,6 +128,7 @@ module GoodJob
|
|
123
128
|
type: :numeric,
|
124
129
|
banner: 'SECONDS',
|
125
130
|
desc: "Delete records finished more than this many seconds ago (env var: GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO, default: 86400)"
|
131
|
+
|
126
132
|
def cleanup_preserved_jobs
|
127
133
|
set_up_application!
|
128
134
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GoodJob
|
2
3
|
#
|
3
4
|
# +GoodJob::Configuration+ provides normalized configuration information to
|
@@ -17,6 +18,8 @@ module GoodJob
|
|
17
18
|
DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO = 24 * 60 * 60
|
18
19
|
# Default to always wait for jobs to finish for {Adapter#shutdown}
|
19
20
|
DEFAULT_SHUTDOWN_TIMEOUT = -1
|
21
|
+
# Default to not running cron
|
22
|
+
DEFAULT_ENABLE_CRON = false
|
20
23
|
|
21
24
|
# The options that were explicitly set when initializing +Configuration+.
|
22
25
|
# @return [Hash]
|
@@ -128,6 +131,28 @@ module GoodJob
|
|
128
131
|
).to_f
|
129
132
|
end
|
130
133
|
|
134
|
+
# Whether to run cron
|
135
|
+
# @return [Boolean]
|
136
|
+
def enable_cron
|
137
|
+
value = ActiveModel::Type::Boolean.new.cast(
|
138
|
+
options[:enable_cron] ||
|
139
|
+
rails_config[:enable_cron] ||
|
140
|
+
env['GOOD_JOB_ENABLE_CRON'] ||
|
141
|
+
false
|
142
|
+
)
|
143
|
+
value && cron.size.positive?
|
144
|
+
end
|
145
|
+
alias enable_cron? enable_cron
|
146
|
+
|
147
|
+
def cron
|
148
|
+
env_cron = JSON.parse(ENV['GOOD_JOB_CRON']) if ENV['GOOD_JOB_CRON'].present?
|
149
|
+
|
150
|
+
options[:cron] ||
|
151
|
+
rails_config[:cron] ||
|
152
|
+
env_cron ||
|
153
|
+
{}
|
154
|
+
end
|
155
|
+
|
131
156
|
# Number of seconds to preserve jobs when using the +good_job cleanup_preserved_jobs+ CLI command.
|
132
157
|
# This configuration is only used when {GoodJob.preserve_job_records} is +true+.
|
133
158
|
# @return [Integer]
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "concurrent/hash"
|
3
|
+
require "concurrent/scheduled_task"
|
4
|
+
require "fugit"
|
5
|
+
|
6
|
+
module GoodJob # :nodoc:
|
7
|
+
#
|
8
|
+
# CronManagers enqueue jobs on a repeating schedule.
|
9
|
+
#
|
10
|
+
class CronManager
|
11
|
+
# @!attribute [r] instances
|
12
|
+
# @!scope class
|
13
|
+
# List of all instantiated CronManagers in the current process.
|
14
|
+
# @return [Array<GoodJob::CronManagers>, nil]
|
15
|
+
cattr_reader :instances, default: [], instance_reader: false
|
16
|
+
|
17
|
+
# Task observer for cron task
|
18
|
+
# @param time [Time]
|
19
|
+
# @param output [Object]
|
20
|
+
# @param thread_error [Exception]
|
21
|
+
def self.task_observer(time, output, thread_error) # rubocop:disable Lint/UnusedMethodArgument
|
22
|
+
return if thread_error.is_a? Concurrent::CancelledOperationError
|
23
|
+
|
24
|
+
GoodJob.on_thread_error.call(thread_error) if thread_error && GoodJob.on_thread_error.respond_to?(:call)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Job configuration to be scheduled
|
28
|
+
# @return [Hash]
|
29
|
+
attr_reader :schedules
|
30
|
+
|
31
|
+
# @param schedules [Hash]
|
32
|
+
# @param start_on_initialize [Boolean]
|
33
|
+
def initialize(schedules = {}, start_on_initialize: false)
|
34
|
+
@running = false
|
35
|
+
@schedules = schedules
|
36
|
+
@tasks = Concurrent::Hash.new
|
37
|
+
|
38
|
+
self.class.instances << self
|
39
|
+
|
40
|
+
start if start_on_initialize
|
41
|
+
end
|
42
|
+
|
43
|
+
# Schedule tasks that will enqueue jobs based on their schedule
|
44
|
+
def start
|
45
|
+
ActiveSupport::Notifications.instrument("cron_manager_start.good_job", cron_jobs: @schedules) do
|
46
|
+
@running = true
|
47
|
+
schedules.each_key { |cron_key| create_task(cron_key) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Stop/cancel any scheduled tasks
|
52
|
+
# @param timeout [Numeric, nil] Unused but retained for compatibility
|
53
|
+
def shutdown(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
|
54
|
+
@running = false
|
55
|
+
@tasks.each do |_cron_key, task|
|
56
|
+
task.cancel
|
57
|
+
end
|
58
|
+
@tasks.clear
|
59
|
+
end
|
60
|
+
|
61
|
+
# Stop and restart
|
62
|
+
# @param timeout [Numeric, nil] Unused but retained for compatibility
|
63
|
+
def restart(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
|
64
|
+
shutdown
|
65
|
+
start
|
66
|
+
end
|
67
|
+
|
68
|
+
# Tests whether the manager is running.
|
69
|
+
# @return [Boolean, nil]
|
70
|
+
def running?
|
71
|
+
@running
|
72
|
+
end
|
73
|
+
|
74
|
+
# Tests whether the manager is shutdown.
|
75
|
+
# @return [Boolean, nil]
|
76
|
+
def shutdown?
|
77
|
+
!running?
|
78
|
+
end
|
79
|
+
|
80
|
+
# Enqueues a scheduled task
|
81
|
+
# @param cron_key [Symbol, String] the key within the schedule to use
|
82
|
+
def create_task(cron_key)
|
83
|
+
schedule = @schedules[cron_key]
|
84
|
+
return false if schedule.blank?
|
85
|
+
|
86
|
+
fugit = Fugit::Cron.parse(schedule.fetch(:cron))
|
87
|
+
delay = [(fugit.next_time - Time.current).to_f, 0].max
|
88
|
+
|
89
|
+
future = Concurrent::ScheduledTask.new(delay, args: [self, cron_key]) do |thr_scheduler, thr_cron_key|
|
90
|
+
# Re-schedule the next cron task before executing the current task
|
91
|
+
thr_scheduler.create_task(thr_cron_key)
|
92
|
+
|
93
|
+
CurrentExecution.reset
|
94
|
+
CurrentExecution.cron_key = thr_cron_key
|
95
|
+
|
96
|
+
Rails.application.executor.wrap do
|
97
|
+
schedule = thr_scheduler.schedules.fetch(thr_cron_key).with_indifferent_access
|
98
|
+
job_class = schedule.fetch(:class).constantize
|
99
|
+
|
100
|
+
job_set_value = schedule.fetch(:set, {})
|
101
|
+
job_set = job_set_value.respond_to?(:call) ? job_set_value.call : job_set_value
|
102
|
+
|
103
|
+
job_args_value = schedule.fetch(:args, [])
|
104
|
+
job_args = job_args_value.respond_to?(:call) ? job_args_value.call : job_args_value
|
105
|
+
|
106
|
+
job_class.set(job_set).perform_later(*job_args)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
@tasks[cron_key] = future
|
111
|
+
future.add_observer(self.class, :task_observer)
|
112
|
+
future.execute
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'active_support/core_ext/module/attribute_accessors_per_thread'
|
2
3
|
|
3
4
|
module GoodJob
|
@@ -10,6 +11,12 @@ module GoodJob
|
|
10
11
|
# @return [String, nil]
|
11
12
|
thread_mattr_accessor :active_job_id
|
12
13
|
|
14
|
+
# @!attribute [rw] cron_key
|
15
|
+
# @!scope class
|
16
|
+
# Cron Key
|
17
|
+
# @return [String, nil]
|
18
|
+
thread_mattr_accessor :cron_key
|
19
|
+
|
13
20
|
# @!attribute [rw] error_on_discard
|
14
21
|
# @!scope class
|
15
22
|
# Error captured by discard_on
|
data/lib/good_job/daemon.rb
CHANGED
data/lib/good_job/job.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GoodJob
|
2
3
|
# ActiveRecord model that represents an +ActiveJob+ job.
|
3
4
|
# Parent class can be configured with +GoodJob.active_record_parent_class+.
|
@@ -10,11 +11,12 @@ module GoodJob
|
|
10
11
|
PreviouslyPerformedError = Class.new(StandardError)
|
11
12
|
|
12
13
|
# ActiveJob jobs without a +queue_name+ attribute are placed on this queue.
|
13
|
-
DEFAULT_QUEUE_NAME = 'default'
|
14
|
+
DEFAULT_QUEUE_NAME = 'default'
|
14
15
|
# ActiveJob jobs without a +priority+ attribute are given this priority.
|
15
16
|
DEFAULT_PRIORITY = 0
|
16
17
|
|
17
|
-
self.table_name = 'good_jobs'
|
18
|
+
self.table_name = 'good_jobs'
|
19
|
+
self.advisory_lockable_column = 'id'
|
18
20
|
|
19
21
|
attr_readonly :serialized_params
|
20
22
|
|
@@ -197,6 +199,7 @@ module GoodJob
|
|
197
199
|
def self.enqueue(active_job, scheduled_at: nil, create_with_advisory_lock: false)
|
198
200
|
ActiveSupport::Notifications.instrument("enqueue_job.good_job", { active_job: active_job, scheduled_at: scheduled_at, create_with_advisory_lock: create_with_advisory_lock }) do |instrument_payload|
|
199
201
|
good_job_args = {
|
202
|
+
cron_key: CurrentExecution.cron_key,
|
200
203
|
queue_name: active_job.queue_name.presence || DEFAULT_QUEUE_NAME,
|
201
204
|
priority: active_job.priority || DEFAULT_PRIORITY,
|
202
205
|
serialized_params: active_job.serialize,
|
@@ -283,6 +286,25 @@ module GoodJob
|
|
283
286
|
super || serialized_params['job_id']
|
284
287
|
end
|
285
288
|
|
289
|
+
def cron_key
|
290
|
+
if self.class.column_names.include?('cron_key')
|
291
|
+
super
|
292
|
+
else
|
293
|
+
ActiveSupport::Deprecation.warn(<<~DEPRECATION)
|
294
|
+
GoodJob has pending database migrations. To create the migration files, run:
|
295
|
+
|
296
|
+
rails generate good_job:update
|
297
|
+
|
298
|
+
To apply the migration files, run:
|
299
|
+
|
300
|
+
rails db:migrate
|
301
|
+
|
302
|
+
DEPRECATION
|
303
|
+
|
304
|
+
nil
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
286
308
|
private
|
287
309
|
|
288
310
|
# @return [ExecutionResult]
|
@@ -293,6 +315,7 @@ module GoodJob
|
|
293
315
|
|
294
316
|
GoodJob::CurrentExecution.reset
|
295
317
|
GoodJob::CurrentExecution.active_job_id = active_job_id
|
318
|
+
GoodJob::CurrentExecution.cron_key = cron_key
|
296
319
|
ActiveSupport::Notifications.instrument("perform_job.good_job", { good_job: self, process_id: GoodJob::CurrentExecution.process_id, thread_name: GoodJob::CurrentExecution.thread_name }) do
|
297
320
|
value = ActiveJob::Base.execute(params)
|
298
321
|
|
data/lib/good_job/lockable.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GoodJob
|
2
3
|
#
|
3
4
|
# Listens to GoodJob notifications and logs them.
|
@@ -56,6 +57,16 @@ module GoodJob
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
# @!macro notification_responder
|
61
|
+
def cron_manager_start(event)
|
62
|
+
cron_jobs = event.payload[:cron_jobs]
|
63
|
+
cron_jobs_count = cron_jobs.size
|
64
|
+
|
65
|
+
info do
|
66
|
+
"GoodJob started cron with #{cron_jobs_count} #{'jobs'.pluralize(cron_jobs_count)}."
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
59
70
|
# @!macro notification_responder
|
60
71
|
def scheduler_shutdown_start(event)
|
61
72
|
process_id = event.payload[:process_id]
|
data/lib/good_job/notifier.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'concurrent/atomic/atomic_boolean'
|
2
3
|
|
3
4
|
module GoodJob # :nodoc:
|
@@ -13,7 +14,7 @@ module GoodJob # :nodoc:
|
|
13
14
|
AdapterCannotListenError = Class.new(StandardError)
|
14
15
|
|
15
16
|
# Default Postgres channel for LISTEN/NOTIFY
|
16
|
-
CHANNEL = 'good_job'
|
17
|
+
CHANNEL = 'good_job'
|
17
18
|
# Defaults for instance of Concurrent::ThreadPoolExecutor
|
18
19
|
EXECUTOR_OPTIONS = {
|
19
20
|
name: name,
|
@@ -24,6 +25,8 @@ module GoodJob # :nodoc:
|
|
24
25
|
max_queue: 1,
|
25
26
|
fallback_policy: :discard,
|
26
27
|
}.freeze
|
28
|
+
# Seconds to wait if database cannot be connected to
|
29
|
+
RECONNECT_INTERVAL = 5
|
27
30
|
# Seconds to block while LISTENing for a message
|
28
31
|
WAIT_INTERVAL = 1
|
29
32
|
|
@@ -114,7 +117,13 @@ module GoodJob # :nodoc:
|
|
114
117
|
ActiveSupport::Notifications.instrument("notifier_notify_error.good_job", { error: thread_error })
|
115
118
|
end
|
116
119
|
|
117
|
-
|
120
|
+
return if shutdown?
|
121
|
+
|
122
|
+
if thread_error.is_a?(ActiveRecord::ConnectionNotEstablished) || thread_error.is_a?(ActiveRecord::StatementInvalid)
|
123
|
+
listen(delay: RECONNECT_INTERVAL)
|
124
|
+
else
|
125
|
+
listen
|
126
|
+
end
|
118
127
|
end
|
119
128
|
|
120
129
|
private
|
@@ -125,8 +134,8 @@ module GoodJob # :nodoc:
|
|
125
134
|
@executor = Concurrent::ThreadPoolExecutor.new(EXECUTOR_OPTIONS)
|
126
135
|
end
|
127
136
|
|
128
|
-
def listen
|
129
|
-
future = Concurrent::
|
137
|
+
def listen(delay: 0)
|
138
|
+
future = Concurrent::ScheduledTask.new(delay, args: [@recipients, executor, @listening], executor: @executor) do |thr_recipients, thr_executor, thr_listening|
|
130
139
|
with_listen_connection do |conn|
|
131
140
|
ActiveSupport::Notifications.instrument("notifier_listen.good_job") do
|
132
141
|
conn.async_exec("LISTEN #{CHANNEL}").clear
|
data/lib/good_job/poller.rb
CHANGED
data/lib/good_job/railtie.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GoodJob
|
2
3
|
# Ruby on Rails integration.
|
3
4
|
class Railtie < ::Rails::Railtie
|
4
5
|
config.good_job = ActiveSupport::OrderedOptions.new
|
6
|
+
config.good_job.cron = {}
|
5
7
|
|
6
8
|
initializer "good_job.logger" do |_app|
|
7
9
|
ActiveSupport.on_load(:good_job) do
|
@@ -22,6 +24,7 @@ module GoodJob
|
|
22
24
|
|
23
25
|
config.after_initialize do
|
24
26
|
GoodJob::Scheduler.instances.each(&:warm_cache)
|
27
|
+
GoodJob::CronManager.instances.each(&:start)
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
data/lib/good_job/scheduler.rb
CHANGED
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.12.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: 2021-
|
11
|
+
date: 2021-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.0.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fugit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: railties
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -345,12 +359,12 @@ files:
|
|
345
359
|
- engine/app/helpers/good_job/application_helper.rb
|
346
360
|
- engine/app/views/good_job/active_jobs/show.html.erb
|
347
361
|
- engine/app/views/good_job/dashboards/index.html.erb
|
362
|
+
- engine/app/views/good_job/shared/_chart.erb
|
363
|
+
- engine/app/views/good_job/shared/_jobs_table.erb
|
364
|
+
- engine/app/views/good_job/shared/icons/_check.html.erb
|
365
|
+
- engine/app/views/good_job/shared/icons/_exclamation.html.erb
|
366
|
+
- engine/app/views/good_job/shared/icons/_trash.html.erb
|
348
367
|
- engine/app/views/layouts/good_job/base.html.erb
|
349
|
-
- engine/app/views/shared/_chart.erb
|
350
|
-
- engine/app/views/shared/_jobs_table.erb
|
351
|
-
- engine/app/views/shared/icons/_check.html.erb
|
352
|
-
- engine/app/views/shared/icons/_exclamation.html.erb
|
353
|
-
- engine/app/views/shared/icons/_trash.html.erb
|
354
368
|
- engine/config/routes.rb
|
355
369
|
- engine/lib/good_job/engine.rb
|
356
370
|
- exe/good_job
|
@@ -367,6 +381,7 @@ files:
|
|
367
381
|
- lib/good_job/adapter.rb
|
368
382
|
- lib/good_job/cli.rb
|
369
383
|
- lib/good_job/configuration.rb
|
384
|
+
- lib/good_job/cron_manager.rb
|
370
385
|
- lib/good_job/current_execution.rb
|
371
386
|
- lib/good_job/daemon.rb
|
372
387
|
- lib/good_job/execution_result.rb
|