good_job 1.11.2 → 1.12.2

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -6
  3. data/README.md +93 -4
  4. data/engine/app/controllers/good_job/active_jobs_controller.rb +1 -0
  5. data/engine/app/controllers/good_job/assets_controller.rb +1 -0
  6. data/engine/app/controllers/good_job/base_controller.rb +1 -0
  7. data/engine/app/controllers/good_job/dashboards_controller.rb +1 -0
  8. data/engine/app/controllers/good_job/jobs_controller.rb +1 -0
  9. data/engine/app/helpers/good_job/application_helper.rb +1 -0
  10. data/engine/app/views/good_job/active_jobs/show.html.erb +1 -1
  11. data/engine/app/views/good_job/dashboards/index.html.erb +2 -2
  12. data/engine/app/views/{shared → good_job/shared}/_chart.erb +2 -2
  13. data/engine/app/views/{shared → good_job/shared}/_jobs_table.erb +1 -1
  14. data/engine/app/views/{shared → good_job/shared}/icons/_check.html.erb +0 -0
  15. data/engine/app/views/{shared → good_job/shared}/icons/_exclamation.html.erb +0 -0
  16. data/engine/app/views/{shared → good_job/shared}/icons/_trash.html.erb +0 -0
  17. data/engine/app/views/layouts/good_job/base.html.erb +7 -7
  18. data/engine/config/routes.rb +11 -5
  19. data/engine/lib/good_job/engine.rb +1 -0
  20. data/exe/good_job +1 -0
  21. data/lib/active_job/queue_adapters/good_job_adapter.rb +1 -0
  22. data/lib/generators/good_job/install_generator.rb +1 -0
  23. data/lib/generators/good_job/templates/update/migrations/01_create_good_jobs.rb +1 -0
  24. data/lib/generators/good_job/templates/update/migrations/02_add_active_job_id_concurrency_key_cron_key_to_good_jobs.rb +1 -0
  25. data/lib/generators/good_job/templates/update/migrations/03_add_active_job_id_index_and_concurrency_key_index_to_good_jobs.rb +1 -0
  26. data/lib/generators/good_job/update_generator.rb +1 -0
  27. data/lib/good_job.rb +16 -10
  28. data/lib/good_job/active_job_extensions.rb +1 -0
  29. data/lib/good_job/active_job_extensions/concurrency.rb +8 -7
  30. data/lib/good_job/adapter.rb +3 -0
  31. data/lib/good_job/cli.rb +8 -2
  32. data/lib/good_job/configuration.rb +25 -0
  33. data/lib/good_job/cron_manager.rb +115 -0
  34. data/lib/good_job/current_execution.rb +7 -0
  35. data/lib/good_job/daemon.rb +1 -0
  36. data/lib/good_job/execution_result.rb +1 -0
  37. data/lib/good_job/job.rb +25 -3
  38. data/lib/good_job/job_performer.rb +1 -0
  39. data/lib/good_job/lockable.rb +1 -0
  40. data/lib/good_job/log_subscriber.rb +11 -0
  41. data/lib/good_job/multi_scheduler.rb +1 -0
  42. data/lib/good_job/notifier.rb +2 -1
  43. data/lib/good_job/poller.rb +1 -0
  44. data/lib/good_job/railtie.rb +3 -0
  45. data/lib/good_job/scheduler.rb +1 -0
  46. data/lib/good_job/version.rb +2 -1
  47. metadata +22 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d78c670393e4cddbedfe9512fdda95855709d830618cd63cfde7e724f26ce6c8
4
- data.tar.gz: 494d3b0d6ec2b05d0bcc3386c14baca6071635647ed808a9b3543b5f1ebc4bfb
3
+ metadata.gz: 0af2c2293c2a0970a95ac200776850daa396a91d75aeda3f4612de23ee951a5c
4
+ data.tar.gz: c938c0efca849771e68b39634e56fbdacf2987a83bdf8115e8050b9c49da40c3
5
5
  SHA512:
6
- metadata.gz: bef7307febc465eab519c44a214287d5203bf0a024d83e46160dbbaf94b3a0fcd1317fbe99e446d9b0f01fb2bc8845a6dfe722fb123020aab96fe31b0c189d71
7
- data.tar.gz: 737c03b9ad35169c9db43070abca6f644816876217fd333831db568f43eca6738dd9327eb7a403eb901ab6643e06445ba7764453d3f9b05e9e7c1159f7ba0963
6
+ metadata.gz: 3b4da4eec468271fc88260fc0abcdb6faaaa9e43532e5587338fdca0a4f92f89d4e4f780678fe2c74a714adb0e7a1af263fb0578193382ee8181e11c44aea20d
7
+ data.tar.gz: 91f4ae034471774f5ec1915750ccbf1d9d6ad9cc68df4f5ffa4c0bf6bca57928115e6871a59d30d6bab79b22faa7a4a293d55f55c1bf2cc659d55c0c60049040
data/CHANGELOG.md CHANGED
@@ -1,5 +1,67 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.12.2](https://github.com/bensheldon/good_job/tree/v1.12.2) (2021-08-13)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.12.1...v1.12.2)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Fixes for race conditions in ActiveJob concurrency extension [\#326](https://github.com/bensheldon/good_job/pull/326) ([codyrobbins](https://github.com/codyrobbins))
10
+
11
+ **Merged pull requests:**
12
+
13
+ - On gem release, add instructions to author a Github Release [\#324](https://github.com/bensheldon/good_job/pull/324) ([bensheldon](https://github.com/bensheldon))
14
+
15
+ ## [v1.12.1](https://github.com/bensheldon/good_job/tree/v1.12.1) (2021-08-05)
16
+
17
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.12.0...v1.12.1)
18
+
19
+ **Fixed bugs:**
20
+
21
+ - Ensure CLI can shutdown cleanly with multiple queues and timeout [\#319](https://github.com/bensheldon/good_job/pull/319) ([bensheldon](https://github.com/bensheldon))
22
+
23
+ **Closed issues:**
24
+
25
+ - Setting a shutdown timeout causes the CLI executor to throw an exception on shutdown. [\#318](https://github.com/bensheldon/good_job/issues/318)
26
+ - PgBouncer and prepared statements [\#269](https://github.com/bensheldon/good_job/issues/269)
27
+ - Question about locking internals [\#212](https://github.com/bensheldon/good_job/issues/212)
28
+ - Encoding::UndefinedConversionError \("\xE2" from ASCII-8BIT to UTF-8\) [\#198](https://github.com/bensheldon/good_job/issues/198)
29
+ - tools for managing a 'fleet' of processes [\#150](https://github.com/bensheldon/good_job/issues/150)
30
+
31
+ **Merged pull requests:**
32
+
33
+ - Fix Readme lint warnings [\#320](https://github.com/bensheldon/good_job/pull/320) ([bensheldon](https://github.com/bensheldon))
34
+
35
+ ## [v1.12.0](https://github.com/bensheldon/good_job/tree/v1.12.0) (2021-07-27)
36
+
37
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.3...v1.12.0)
38
+
39
+ **Implemented enhancements:**
40
+
41
+ - Add the ability to schedule repeating / recurring / cron-like jobs [\#53](https://github.com/bensheldon/good_job/issues/53)
42
+ - Add cron-like support for recurring/repeating jobs [\#297](https://github.com/bensheldon/good_job/pull/297) ([bensheldon](https://github.com/bensheldon))
43
+
44
+ **Fixed bugs:**
45
+
46
+ - Place Dashboard shared view partials under `good_job` namespace [\#310](https://github.com/bensheldon/good_job/pull/310) ([bensheldon](https://github.com/bensheldon))
47
+ - 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))
48
+
49
+ ## [v1.11.3](https://github.com/bensheldon/good_job/tree/v1.11.3) (2021-07-25)
50
+
51
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.2...v1.11.3)
52
+
53
+ **Closed issues:**
54
+
55
+ - ERROR: relation "good\_jobs" does not exist at character 454 [\#308](https://github.com/bensheldon/good_job/issues/308)
56
+ - Add Frozen String Literal to all files [\#298](https://github.com/bensheldon/good_job/issues/298)
57
+ - Support for good\_job without Rails? [\#295](https://github.com/bensheldon/good_job/issues/295)
58
+
59
+ **Merged pull requests:**
60
+
61
+ - 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))
62
+ - Create dashboard demo app on Heroku [\#305](https://github.com/bensheldon/good_job/pull/305) ([bensheldon](https://github.com/bensheldon))
63
+ - Add Frozen String Literal to all files [\#302](https://github.com/bensheldon/good_job/pull/302) ([tedhexaflow](https://github.com/tedhexaflow))
64
+
3
65
  ## [v1.11.2](https://github.com/bensheldon/good_job/tree/v1.11.2) (2021-07-20)
4
66
 
5
67
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.1...v1.11.2)
@@ -22,13 +84,13 @@
22
84
 
23
85
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.11.0...v1.11.1)
24
86
 
25
- **Closed issues:**
87
+ **Fixed bugs:**
26
88
 
27
- - Database connection required while loading the code on 1.10.x [\#291](https://github.com/bensheldon/good_job/issues/291)
89
+ - Defer accessing ActiveRecord `primary_key` in Lockable [\#293](https://github.com/bensheldon/good_job/pull/293) ([bensheldon](https://github.com/bensheldon))
28
90
 
29
- **Merged pull requests:**
91
+ **Closed issues:**
30
92
 
31
- - Defer accessing ActiveRecord `primary_key` in Lockable [\#293](https://github.com/bensheldon/good_job/pull/293) ([bensheldon](https://github.com/bensheldon))
93
+ - Database connection required while loading the code on 1.10.x [\#291](https://github.com/bensheldon/good_job/issues/291)
32
94
 
33
95
  ## [v1.11.0](https://github.com/bensheldon/good_job/tree/v1.11.0) (2021-07-07)
34
96
 
@@ -50,9 +112,12 @@
50
112
 
51
113
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.10.0...v1.10.1)
52
114
 
53
- **Merged pull requests:**
115
+ **Fixed bugs:**
54
116
 
55
117
  - Remove `FOR UPDATE SKIP LOCKED` from job locking sql statement [\#288](https://github.com/bensheldon/good_job/pull/288) ([bensheldon](https://github.com/bensheldon))
118
+
119
+ **Merged pull requests:**
120
+
56
121
  - 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))
57
122
 
58
123
  ## [v1.10.0](https://github.com/bensheldon/good_job/tree/v1.10.0) (2021-06-29)
@@ -61,11 +126,11 @@
61
126
 
62
127
  **Implemented enhancements:**
63
128
 
129
+ - 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))
64
130
  - 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))
65
131
 
66
132
  **Fixed bugs:**
67
133
 
68
- - 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))
69
134
  - 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))
70
135
 
71
136
  **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 Concurrency](#activejob-concurrency)
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 Concurrency
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,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  class ActiveJobsController < GoodJob::BaseController
3
4
  def show
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  class AssetsController < ActionController::Base # rubocop:disable Rails/ApplicationController
3
4
  skip_before_action :verify_authenticity_token, raise: false
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  class BaseController < ActionController::Base # rubocop:disable Rails/ApplicationController
3
4
  protect_from_forgery with: :exception
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  class DashboardsController < GoodJob::BaseController
3
4
  class JobFilter
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  class JobsController < GoodJob::BaseController
3
4
  def destroy
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  module ApplicationHelper
3
4
  end
@@ -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
- <script>
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
- </script>
52
+ <% end %>
@@ -29,7 +29,7 @@
29
29
  </td>
30
30
  <td>
31
31
  <%= button_to job_path(job.id), method: :delete, class: "btn btn-sm btn-outline-danger", title: "Delete job" do %>
32
- <%= render "shared/icons/trash" %>
32
+ <%= render "good_job/shared/icons/trash" %>
33
33
  <% end %>
34
34
  </td>
35
35
  </tr>
@@ -5,12 +5,12 @@
5
5
  <%= csrf_meta_tags %>
6
6
  <%= csp_meta_tag %>
7
7
 
8
- <%= stylesheet_link_tag bootstrap_css_path(v: GoodJob::VERSION) %>
9
- <%= stylesheet_link_tag chartist_css_path(v: GoodJob::VERSION) %>
10
- <%= stylesheet_link_tag style_css_path(v: GoodJob::VERSION) %>
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 bootstrap_js_path(v: GoodJob::VERSION) %>
13
- <%= javascript_include_tag chartist_js_path(v: GoodJob::VERSION) %>
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>
@@ -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
- get :bootstrap_css
8
- get :bootstrap_js
9
- get :chartist_css
10
- get :chartist_js
11
- get :style_css
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  class Engine < ::Rails::Engine
3
4
  isolate_namespace GoodJob
data/exe/good_job CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  require 'good_job/cli'
3
4
 
4
5
  GoodJob::CLI.within_exe = true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveJob # :nodoc:
2
3
  module QueueAdapters # :nodoc:
3
4
  # See {GoodJob::Adapter} for details.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/generators'
2
3
  require 'rails/generators/active_record'
3
4
  module GoodJob
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class CreateGoodJobs < ActiveRecord::Migration[5.2]
2
3
  def change
3
4
  enable_extension 'pgcrypto'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class AddActiveJobIdConcurrencyKeyCronKeyToGoodJobs < ActiveRecord::Migration[5.2]
2
3
  def change
3
4
  reversible do |dir|
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class AddActiveJobIdIndexAndConcurrencyKeyIndexToGoodJobs < ActiveRecord::Migration[5.2]
2
3
  disable_ddl_transaction!
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/generators'
2
3
  require 'rails/generators/active_record'
3
4
 
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
- executables = Array(Notifier.instances) + Array(Poller.instances) + Array(Scheduler.instances)
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
- Notifier.instances.all?(&:shutdown?) &&
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
- executables = Array(Notifier.instances) + Array(Poller.instances) + Array(Scheduler.instances)
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  module ActiveJobExtensions
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  module ActiveJobExtensions
3
4
  module Concurrency
@@ -8,21 +9,21 @@ module GoodJob
8
9
  included do
9
10
  class_attribute :good_job_concurrency_config, instance_accessor: false, default: {}
10
11
 
11
- before_enqueue do |job|
12
+ around_enqueue do |job, block|
12
13
  # Always allow jobs to be retried because the current job's execution will complete momentarily
13
- next if CurrentExecution.active_job_id == job.job_id
14
+ next(block.call) if CurrentExecution.active_job_id == job.job_id
14
15
 
15
16
  limit = job.class.good_job_concurrency_config.fetch(:enqueue_limit, Float::INFINITY)
16
- next if limit.blank? || (0...Float::INFINITY).exclude?(limit)
17
+ next(block.call) if limit.blank? || (0...Float::INFINITY).exclude?(limit)
17
18
 
18
19
  key = job.good_job_concurrency_key
19
- next if key.blank?
20
+ next(block.call) if key.blank?
20
21
 
21
22
  GoodJob::Job.new.with_advisory_lock(key: key, function: "pg_advisory_lock") do
22
23
  # TODO: Why is `unscoped` necessary? Nested scope is bleeding into subsequent query?
23
24
  enqueue_concurrency = GoodJob::Job.unscoped.where(concurrency_key: key).unfinished.count
24
25
  # The job has not yet been enqueued, so check if adding it will go over the limit
25
- throw :abort if enqueue_concurrency + 1 > limit
26
+ block.call unless enqueue_concurrency + 1 > limit
26
27
  end
27
28
  end
28
29
 
@@ -40,9 +41,9 @@ module GoodJob
40
41
  next if key.blank?
41
42
 
42
43
  GoodJob::Job.new.with_advisory_lock(key: key, function: "pg_advisory_lock") do
43
- perform_concurrency = GoodJob::Job.unscoped.where(concurrency_key: key).advisory_locked.count
44
+ allowed_active_job_ids = GoodJob::Job.unscoped.where(concurrency_key: key).advisory_locked.order(Arel.sql("COALESCE(performed_at, scheduled_at, created_at) ASC")).limit(limit).pluck(:active_job_id)
44
45
  # The current job has already been locked and will appear in the previous query
45
- raise GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError if perform_concurrency > limit
46
+ raise GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError unless allowed_active_job_ids.include? job.job_id
46
47
  end
47
48
  end
48
49
  end
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  #
3
4
  # Manages daemonization of the current process.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  # Stores the results of job execution
3
4
  class ExecutionResult
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,12 +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'.freeze
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'.freeze
18
- self.advisory_lockable_column = 'id'.freeze
18
+ self.table_name = 'good_jobs'
19
+ self.advisory_lockable_column = 'id'
19
20
 
20
21
  attr_readonly :serialized_params
21
22
 
@@ -198,6 +199,7 @@ module GoodJob
198
199
  def self.enqueue(active_job, scheduled_at: nil, create_with_advisory_lock: false)
199
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|
200
201
  good_job_args = {
202
+ cron_key: CurrentExecution.cron_key,
201
203
  queue_name: active_job.queue_name.presence || DEFAULT_QUEUE_NAME,
202
204
  priority: active_job.priority || DEFAULT_PRIORITY,
203
205
  serialized_params: active_job.serialize,
@@ -284,6 +286,25 @@ module GoodJob
284
286
  super || serialized_params['job_id']
285
287
  end
286
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
+
287
308
  private
288
309
 
289
310
  # @return [ExecutionResult]
@@ -294,6 +315,7 @@ module GoodJob
294
315
 
295
316
  GoodJob::CurrentExecution.reset
296
317
  GoodJob::CurrentExecution.active_job_id = active_job_id
318
+ GoodJob::CurrentExecution.cron_key = cron_key
297
319
  ActiveSupport::Notifications.instrument("perform_job.good_job", { good_job: self, process_id: GoodJob::CurrentExecution.process_id, thread_name: GoodJob::CurrentExecution.thread_name }) do
298
320
  value = ActiveJob::Base.execute(params)
299
321
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'concurrent/delay'
2
3
 
3
4
  module GoodJob
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  #
3
4
  # Adds Postgres advisory locking capabilities to an ActiveRecord record.
@@ -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]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  # Delegates the interface of a single {Scheduler} to multiple Schedulers.
3
4
  class MultiScheduler
@@ -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'.freeze
17
+ CHANNEL = 'good_job'
17
18
  # Defaults for instance of Concurrent::ThreadPoolExecutor
18
19
  EXECUTOR_OPTIONS = {
19
20
  name: name,
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'concurrent/atomic/atomic_boolean'
2
3
 
3
4
  module GoodJob # :nodoc:
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "concurrent/executor/thread_pool_executor"
2
3
  require "concurrent/executor/timer_set"
3
4
  require "concurrent/scheduled_task"
@@ -1,4 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  module GoodJob
2
3
  # GoodJob gem version.
3
- VERSION = '1.11.2'.freeze
4
+ VERSION = '1.12.2'
4
5
  end
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.11.2
4
+ version: 1.12.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: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-08-13 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