good_job 1.2.4 → 1.3.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +119 -8
  3. data/README.md +77 -25
  4. data/engine/app/controllers/good_job/active_jobs_controller.rb +8 -0
  5. data/engine/app/controllers/good_job/base_controller.rb +5 -0
  6. data/engine/app/controllers/good_job/dashboards_controller.rb +50 -0
  7. data/engine/app/helpers/good_job/application_helper.rb +4 -0
  8. data/engine/app/views/assets/_style.css.erb +16 -0
  9. data/engine/app/views/good_job/active_jobs/show.html.erb +1 -0
  10. data/engine/app/views/good_job/dashboards/index.html.erb +19 -0
  11. data/engine/app/views/layouts/good_job/base.html.erb +61 -0
  12. data/engine/app/views/shared/_chart.erb +51 -0
  13. data/engine/app/views/shared/_jobs_table.erb +26 -0
  14. data/engine/app/views/vendor/bootstrap/_bootstrap-native.js.erb +1662 -0
  15. data/engine/app/views/vendor/bootstrap/_bootstrap.css.erb +10258 -0
  16. data/engine/app/views/vendor/chartist/_chartist.css.erb +613 -0
  17. data/engine/app/views/vendor/chartist/_chartist.js.erb +4516 -0
  18. data/engine/config/routes.rb +4 -0
  19. data/engine/lib/good_job/engine.rb +5 -0
  20. data/lib/active_job/queue_adapters/good_job_adapter.rb +3 -2
  21. data/lib/generators/good_job/install_generator.rb +8 -0
  22. data/lib/good_job.rb +59 -26
  23. data/lib/good_job/adapter.rb +41 -0
  24. data/lib/good_job/cli.rb +35 -9
  25. data/lib/good_job/configuration.rb +54 -3
  26. data/lib/good_job/job.rb +126 -36
  27. data/lib/good_job/lockable.rb +126 -13
  28. data/lib/good_job/log_subscriber.rb +80 -16
  29. data/lib/good_job/multi_scheduler.rb +20 -5
  30. data/lib/good_job/notifier.rb +57 -31
  31. data/lib/good_job/performer.rb +38 -0
  32. data/lib/good_job/poller.rb +94 -0
  33. data/lib/good_job/railtie.rb +1 -0
  34. data/lib/good_job/scheduler.rb +54 -81
  35. data/lib/good_job/version.rb +2 -1
  36. metadata +112 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f3fa6d323c18dfb49aaf3b87f0ca71492a935752e7ca140880b68daa72a60f9
4
- data.tar.gz: 999b400b7e1dd22206898fb1cdc35f6255088ce94c3562fa48fe97fc20a23672
3
+ metadata.gz: ff96dcfb5fdd4d48310e8af09ac8785a6d76810f5433b27d3a80c3d3cd8c9d81
4
+ data.tar.gz: e69150fe9a19b21dcada1cccec6d120146131746b09f2633da7320d4cbedee0f
5
5
  SHA512:
6
- metadata.gz: 1b9236562e20d4da1e5738d9b143fabe9377d854b392b6b0eb2d77c0009d9f8a0c82ef94b414446a7b5db0b2a43e477ad4b8a6c7bff737b69c9d8a744ee29151
7
- data.tar.gz: cfcc994ea2f6e9a26c3b1115ccb2df6383e2897c3db891415745b86769dbdc411a62b7d60c89aa7ddb6880009c6124c795cef33efff55daa860ed7fd90e1b81d
6
+ metadata.gz: 782b425219f7538517be26275ced947759e7691b485832f288b4f13df5e112d678b0cc0a1b8589b64f87823b88210f8af6af453dfc36dcdc7bb37a5a9288837b
7
+ data.tar.gz: 57e8f1b790a9d52c6e3774b5a6fdb61a4f43503a0ee3f018a9ad85d39aca9dc2994d2298607bbb48d9fd0d57861de56ef02506b791bd2fa52561910b6d73a586
@@ -1,5 +1,113 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.3.2](https://github.com/bensheldon/good_job/tree/v1.3.2) (2020-11-12)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.3.1...v1.3.2)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - \(bug\) MultiScheduler polling bug [\#171](https://github.com/bensheldon/good_job/issues/171)
10
+ - MultiScheduler should delegate to all schedulers when state is nil [\#172](https://github.com/bensheldon/good_job/pull/172) ([bensheldon](https://github.com/bensheldon))
11
+
12
+ ## [v1.3.1](https://github.com/bensheldon/good_job/tree/v1.3.1) (2020-11-01)
13
+
14
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.3.0...v1.3.1)
15
+
16
+ **Implemented enhancements:**
17
+
18
+ - Extract polling from scheduler into Polling object [\#128](https://github.com/bensheldon/good_job/issues/128)
19
+ - Format serialized params to ease reading [\#170](https://github.com/bensheldon/good_job/pull/170) ([morgoth](https://github.com/morgoth))
20
+
21
+ **Fixed bugs:**
22
+
23
+ - Don't disconnect a nil activerecord connection [\#161](https://github.com/bensheldon/good_job/pull/161) ([bensheldon](https://github.com/bensheldon))
24
+
25
+ **Closed issues:**
26
+
27
+ - Propose addition of GoodJob to queue-shootout benchmarks [\#40](https://github.com/bensheldon/good_job/issues/40)
28
+
29
+ **Merged pull requests:**
30
+
31
+ - Ensure Rails is a development dependency [\#169](https://github.com/bensheldon/good_job/pull/169) ([bensheldon](https://github.com/bensheldon))
32
+ - Fix Ruby 2.7 GH action by setting default bundler explicitly [\#166](https://github.com/bensheldon/good_job/pull/166) ([bensheldon](https://github.com/bensheldon))
33
+ - Cache ruby version explicitly in Github Action [\#165](https://github.com/bensheldon/good_job/pull/165) ([bensheldon](https://github.com/bensheldon))
34
+ - Update development dependencies, rubocop [\#164](https://github.com/bensheldon/good_job/pull/164) ([bensheldon](https://github.com/bensheldon))
35
+ - Fix intended constant hierarchy of GoodJob::Scheduler::ThreadPoolExecutor [\#158](https://github.com/bensheldon/good_job/pull/158) ([bensheldon](https://github.com/bensheldon))
36
+ - Add bin/test\_app executable for Rails debugging [\#157](https://github.com/bensheldon/good_job/pull/157) ([bensheldon](https://github.com/bensheldon))
37
+ - Extract Scheduler polling behavior to its own object [\#152](https://github.com/bensheldon/good_job/pull/152) ([bensheldon](https://github.com/bensheldon))
38
+
39
+ ## [v1.3.0](https://github.com/bensheldon/good_job/tree/v1.3.0) (2020-10-03)
40
+
41
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.2.6...v1.3.0)
42
+
43
+ **Implemented enhancements:**
44
+
45
+ - Lengthen default poll interval from 1 to 5 seconds [\#156](https://github.com/bensheldon/good_job/pull/156) ([bensheldon](https://github.com/bensheldon))
46
+
47
+ **Merged pull requests:**
48
+
49
+ - Rename reperform\_jobs\_on\_standard\_error to retry\_on\_unhandled\_error [\#154](https://github.com/bensheldon/good_job/pull/154) ([morgoth](https://github.com/morgoth))
50
+
51
+ ## [v1.2.6](https://github.com/bensheldon/good_job/tree/v1.2.6) (2020-09-29)
52
+
53
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.2.5...v1.2.6)
54
+
55
+ **Implemented enhancements:**
56
+
57
+ - Preserve only failed jobs [\#136](https://github.com/bensheldon/good_job/issues/136)
58
+ - 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))
59
+
60
+ **Fixed bugs:**
61
+
62
+ - Fix LogSubscriber notifications for finished\_timer\_task and finished\_job\_task [\#148](https://github.com/bensheldon/good_job/pull/148) ([bensheldon](https://github.com/bensheldon))
63
+
64
+ **Closed issues:**
65
+
66
+ - run-once guarantee? [\#151](https://github.com/bensheldon/good_job/issues/151)
67
+
68
+ **Merged pull requests:**
69
+
70
+ - Add info how to setup basic auth for engine [\#153](https://github.com/bensheldon/good_job/pull/153) ([morgoth](https://github.com/morgoth))
71
+ - Add documentation for Dashboard Rails::Engine [\#149](https://github.com/bensheldon/good_job/pull/149) ([bensheldon](https://github.com/bensheldon))
72
+ - Style cleanup to Job error handling [\#147](https://github.com/bensheldon/good_job/pull/147) ([bensheldon](https://github.com/bensheldon))
73
+ - Replace gerund titles in Readme [\#146](https://github.com/bensheldon/good_job/pull/146) ([bensheldon](https://github.com/bensheldon))
74
+ - Only allow Scheduler to be initialized with max\_threads and poll\_interval; remove full access to pool and timer\_task options [\#137](https://github.com/bensheldon/good_job/pull/137) ([bensheldon](https://github.com/bensheldon))
75
+
76
+ ## [v1.2.5](https://github.com/bensheldon/good_job/tree/v1.2.5) (2020-09-17)
77
+
78
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.2.4...v1.2.5)
79
+
80
+ **Implemented enhancements:**
81
+
82
+ - Use Zeitwerk for auto-loading [\#87](https://github.com/bensheldon/good_job/issues/87)
83
+ - Spike on data dashboard; pull in full Bootstrap CSS and JS [\#131](https://github.com/bensheldon/good_job/pull/131) ([bensheldon](https://github.com/bensheldon))
84
+
85
+ **Fixed bugs:**
86
+
87
+ - `poll-interval=-1` does not disable polling as intended [\#133](https://github.com/bensheldon/good_job/issues/133)
88
+ - 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))
89
+ - Prevent jobs hanging [\#141](https://github.com/bensheldon/good_job/pull/141) ([morgoth](https://github.com/morgoth))
90
+ - Add explicit require\_paths to gemspec for engine [\#134](https://github.com/bensheldon/good_job/pull/134) ([bensheldon](https://github.com/bensheldon))
91
+ - 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))
92
+
93
+ **Closed issues:**
94
+
95
+ - Lint - Introduce line character limits [\#122](https://github.com/bensheldon/good_job/issues/122)
96
+ - Jobs are not processed in multi schema setup. Apartment + GoodJob \( post 1.1.2 \) [\#117](https://github.com/bensheldon/good_job/issues/117)
97
+ - Host a documentation sprint [\#48](https://github.com/bensheldon/good_job/issues/48)
98
+
99
+ **Merged pull requests:**
100
+
101
+ - Test GoodJob against Rails HEAD [\#144](https://github.com/bensheldon/good_job/pull/144) ([bensheldon](https://github.com/bensheldon))
102
+ - Drop Ruby 2.4 support [\#142](https://github.com/bensheldon/good_job/pull/142) ([morgoth](https://github.com/morgoth))
103
+ - Remove arguments from perform method [\#140](https://github.com/bensheldon/good_job/pull/140) ([morgoth](https://github.com/morgoth))
104
+ - Extract "execute" method to reduce "perform" method complexity [\#138](https://github.com/bensheldon/good_job/pull/138) ([morgoth](https://github.com/morgoth))
105
+ - Correct example on how to configure multiple queues by command line. [\#135](https://github.com/bensheldon/good_job/pull/135) ([morgoth](https://github.com/morgoth))
106
+ - Update ActionMailer Job class, to match the default [\#130](https://github.com/bensheldon/good_job/pull/130) ([morgoth](https://github.com/morgoth))
107
+ - Add initial Engine scaffold [\#125](https://github.com/bensheldon/good_job/pull/125) ([bensheldon](https://github.com/bensheldon))
108
+ - Zeitwerk Loader Implementation [\#123](https://github.com/bensheldon/good_job/pull/123) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
109
+ - Update code-level documentation [\#111](https://github.com/bensheldon/good_job/pull/111) ([bensheldon](https://github.com/bensheldon))
110
+
3
111
  ## [v1.2.4](https://github.com/bensheldon/good_job/tree/v1.2.4) (2020-09-01)
4
112
 
5
113
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.2.3...v1.2.4)
@@ -7,6 +115,11 @@
7
115
  **Implemented enhancements:**
8
116
 
9
117
  - Add environment variable to mirror `cleanup\_preserved\_jobs --before-seconds-ago=SECONDS` [\#110](https://github.com/bensheldon/good_job/issues/110)
118
+ - Allow env variable config for cleanups [\#114](https://github.com/bensheldon/good_job/pull/114) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
119
+
120
+ **Fixed bugs:**
121
+
122
+ - Better table name detection for Job queries [\#119](https://github.com/bensheldon/good_job/pull/119) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
10
123
 
11
124
  **Closed issues:**
12
125
 
@@ -17,9 +130,7 @@
17
130
  **Merged pull requests:**
18
131
 
19
132
  - Remove unused PgLocks class [\#120](https://github.com/bensheldon/good_job/pull/120) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
20
- - Better table name detection for Job queries [\#119](https://github.com/bensheldon/good_job/pull/119) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
21
133
  - Fix readme CommandLine option links [\#115](https://github.com/bensheldon/good_job/pull/115) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
22
- - Allow env variable config for cleanups [\#114](https://github.com/bensheldon/good_job/pull/114) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
23
134
  - Have YARD render markdown files with GFM \(Github Flavored Markdown\) [\#113](https://github.com/bensheldon/good_job/pull/113) ([bensheldon](https://github.com/bensheldon))
24
135
  - Add markdownlint to lint readme [\#109](https://github.com/bensheldon/good_job/pull/109) ([bensheldon](https://github.com/bensheldon))
25
136
  - Remove unused method in PgLocks [\#107](https://github.com/bensheldon/good_job/pull/107) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
@@ -88,7 +199,6 @@
88
199
  **Merged pull requests:**
89
200
 
90
201
  - Document GoodJob module [\#83](https://github.com/bensheldon/good_job/pull/83) ([bensheldon](https://github.com/bensheldon))
91
- - Add Postgres LISTEN/NOTIFY support [\#82](https://github.com/bensheldon/good_job/pull/82) ([bensheldon](https://github.com/bensheldon))
92
202
 
93
203
  ## [v1.1.4](https://github.com/bensheldon/good_job/tree/v1.1.4) (2020-08-19)
94
204
 
@@ -101,6 +211,7 @@
101
211
 
102
212
  **Merged pull requests:**
103
213
 
214
+ - Add Postgres LISTEN/NOTIFY support [\#82](https://github.com/bensheldon/good_job/pull/82) ([bensheldon](https://github.com/bensheldon))
104
215
  - Allow Schedulers to filter \#create\_thread to avoid flood of queries when running async with multiple schedulers [\#81](https://github.com/bensheldon/good_job/pull/81) ([bensheldon](https://github.com/bensheldon))
105
216
  - Fully name scheduler threadpools and thread names; refactor CLI STDOUT [\#80](https://github.com/bensheldon/good_job/pull/80) ([bensheldon](https://github.com/bensheldon))
106
217
 
@@ -182,6 +293,10 @@
182
293
 
183
294
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.0.1...v1.0.2)
184
295
 
296
+ **Fixed bugs:**
297
+
298
+ - Fix counting of available execution threads [\#58](https://github.com/bensheldon/good_job/pull/58) ([bensheldon](https://github.com/bensheldon))
299
+
185
300
  **Merged pull requests:**
186
301
 
187
302
  - Add migration generator [\#56](https://github.com/bensheldon/good_job/pull/56) ([thedanbob](https://github.com/thedanbob))
@@ -203,10 +318,6 @@
203
318
 
204
319
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v0.8.2...v0.9.0)
205
320
 
206
- **Fixed bugs:**
207
-
208
- - Fix counting of available execution threads [\#58](https://github.com/bensheldon/good_job/pull/58) ([bensheldon](https://github.com/bensheldon))
209
-
210
321
  **Merged pull requests:**
211
322
 
212
323
  - Allow preservation of finished job records [\#46](https://github.com/bensheldon/good_job/pull/46) ([bensheldon](https://github.com/bensheldon))
@@ -287,7 +398,6 @@
287
398
 
288
399
  - Improve ActiveRecord usage for advisory locking [\#24](https://github.com/bensheldon/good_job/pull/24) ([bensheldon](https://github.com/bensheldon))
289
400
  - Remove support for Rails 5.1 [\#23](https://github.com/bensheldon/good_job/pull/23) ([bensheldon](https://github.com/bensheldon))
290
- - Clean up Gemspec [\#15](https://github.com/bensheldon/good_job/pull/15) ([bensheldon](https://github.com/bensheldon))
291
401
 
292
402
  ## [v0.3.0](https://github.com/bensheldon/good_job/tree/v0.3.0) (2020-03-22)
293
403
 
@@ -315,6 +425,7 @@
315
425
 
316
426
  **Merged pull requests:**
317
427
 
428
+ - Clean up Gemspec [\#15](https://github.com/bensheldon/good_job/pull/15) ([bensheldon](https://github.com/bensheldon))
318
429
  - Set up Rubocop [\#14](https://github.com/bensheldon/good_job/pull/14) ([bensheldon](https://github.com/bensheldon))
319
430
  - Add pg gem as explicit dependency [\#13](https://github.com/bensheldon/good_job/pull/13) ([bensheldon](https://github.com/bensheldon))
320
431
  - Bump nokogiri from 1.10.7 to 1.10.9 [\#12](https://github.com/bensheldon/good_job/pull/12) ([dependabot[bot]](https://github.com/apps/dependabot))
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # GoodJob
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/good_job.svg)](https://rubygems.org/gems/good_job)
4
+ [![Test Status](https://github.com/bensheldon/good_job/workflows/Test/badge.svg)](https://github.com/bensheldon/good_job/actions)
5
+
3
6
  GoodJob is a multithreaded, Postgres-based, ActiveJob backend for Ruby on Rails.
4
7
 
5
8
  **Inspired by [Delayed::Job](https://github.com/collectiveidea/delayed_job) and [Que](https://github.com/que-rb/que), GoodJob is designed for maximum compatibility with Ruby on Rails, ActiveJob, and Postgres to be simple and performant for most workloads.**
@@ -33,7 +36,8 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
33
36
  - [`good_job cleanup_preserved_jobs`](#good_job-cleanup_preserved_jobs)
34
37
  - [Adapter options](#adapter-options)
35
38
  - [Global options](#global-options)
36
- - [Going deeper](#going-deeper)
39
+ - [Dashboard](#dashboard)
40
+ - [Go deeper](#go-deeper)
37
41
  - [Exceptions, retries, and reliability](#exceptions-retries-and-reliability)
38
42
  - [Exceptions](#exceptions)
39
43
  - [Retries](#retries)
@@ -41,12 +45,12 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
41
45
  - [Timeouts](#timeouts)
42
46
  - [Optimize queues, threads, and processes](#optimize-queues-threads-and-processes)
43
47
  - [Database connections](#database-connections)
44
- - [Executing jobs async / in-process](#executing-jobs-async--in-process)
45
- - [Migrating to GoodJob from a different ActiveJob backend](#migrating-to-goodjob-from-a-different-activejob-backend)
46
- - [Monitoring and preserving worked jobs](#monitoring-and-preserving-worked-jobs)
47
- - [Contributing](#contributing)
48
+ - [Execute jobs async / in-process](#execute-jobs-async--in-process)
49
+ - [Migrate to GoodJob from a different ActiveJob backend](#migrate-to-goodjob-from-a-different-activejob-backend)
50
+ - [Monitor and preserve worked jobs](#monitor-and-preserve-worked-jobs)
51
+ - [Contribute](#contribute)
48
52
  - [Gem development](#gem-development)
49
- - [Releasing](#releasing)
53
+ - [Release](#release)
50
54
  - [License](#license)
51
55
 
52
56
  ## Set up
@@ -184,7 +188,7 @@ To use GoodJob, you can set `config.active_job.queue_adapter` to a `:good_job` o
184
188
 
185
189
  - `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:
186
190
  - `:inline` executes jobs immediately in whatever process queued them (usually the web server process). This should only be used in test and development environments.
187
- - `:external` causes the adapter to equeue 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.
191
+ - `: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.
188
192
  - `:async` causes the adapter to execute you jobs in separate threads in whatever process queued them (usually the web process). This is akin to running the command-line tool’s code inside your web server. It can be more economical for small workloads (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.
189
193
  - `max_threads` (integer) sets the maximum number of threads to use when `execution_mode` is set to `:async`. You can also set this with the environment variable `GOOD_JOB_MAX_THREADS`.
190
194
  - `queues` (string) determines which queues to execute jobs from when `execution_mode` is set to `:async`. 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`.
@@ -209,19 +213,64 @@ Good Job’s general behavior can also be configured via several attributes dire
209
213
 
210
214
  - **`GoodJob.logger`** ([Rails Logger](https://api.rubyonrails.org/classes/ActiveSupport/Logger.html)) lets you set a custom logger for GoodJob. It should be an instance of a Rails `Logger`.
211
215
  - **`GoodJob.preserve_job_records`** (boolean) keeps job records in your database even after jobs are completed. (Default: `false`)
212
- - **`GoodJob.reperform_jobs_on_standard_error`** (boolean) causes jobs to be re-queued and retried if they raise an instance of `StandardError`. Instances of `Exception`, like SIGINT, will *always* be retried, regardless of this attribute’s value. (Default: `true`)
213
- - **`GoodJob.on_thread_error`** (proc, lambda, or callable) will be called when a job raises an error. It can be useful for logging errors to bug tracking services, like Sentry or Airbrake.
216
+ - **`GoodJob.retry_on_unhandled_error`** (boolean) causes jobs to be re-queued and retried if they raise an instance of `StandardError`. Instances of `Exception`, like SIGINT, will *always* be retried, regardless of this attribute’s value. (Default: `true`)
217
+ - **`GoodJob.on_thread_error`** (proc, lambda, or callable) will be called when an Exception. It can be useful for logging errors to bug tracking services, like Sentry or Airbrake.
214
218
 
215
219
  You’ll generally want to configure these in `config/initializers/good_job.rb`, like so:
216
220
 
217
221
  ```ruby
218
222
  # config/initializers/good_job.rb
219
223
  GoodJob.preserve_job_records = true
220
- GoodJob.reperform_jobs_on_standard_error = false
224
+ GoodJob.retry_on_unhandled_error = false
221
225
  GoodJob.on_thread_error = -> (exception) { Raven.capture_exception(exception) }
222
226
  ```
223
227
 
224
- ## Going deeper
228
+ ### Dashboard
229
+
230
+ _🚧 GoodJob's dashboard is a work in progress. Please contribute ideas and code on [Github](https://github.com/bensheldon/good_job/issues)._
231
+
232
+ GoodJob includes a Dashboard as a mountable `Rails::Engine`.
233
+
234
+ 1. Explicitly require the Engine code at the top of your `config/application.rb` file, immediately after Rails is required. This is necessary because the mountable engine is an optional feature of GoodJob.
235
+
236
+ ```ruby
237
+ # config/application.rb
238
+ require_relative 'boot'
239
+
240
+ require 'rails/all'
241
+ require 'good_job/engine' # <= Add this line
242
+ # ...
243
+ ```
244
+
245
+ 1. Mount the engine in your `config/routes.rb` file. The following will mount it at `http://example.com/good_job`.
246
+
247
+ ```ruby
248
+ # config/routes.rb
249
+ # ...
250
+ mount GoodJob::Engine => 'good_job'
251
+ ```
252
+
253
+ Because jobs can potentially contain sensitive information, you should authorize access. For example, using Devise's `authenticate` helper, that might look like:
254
+
255
+ ```ruby
256
+ # config/routes.rb
257
+ # ...
258
+ authenticate :user, ->(user) { user.admin? } do
259
+ mount GoodJob::Engine => 'good_job'
260
+ end
261
+ ```
262
+
263
+ Another option is using basic auth like this:
264
+
265
+ ```ruby
266
+ # config/initializers/good_job.rb
267
+ GoodJob::Engine.middleware.use(Rack::Auth::Basic) do |username, password|
268
+ ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.good_job_username, username) &&
269
+ ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.good_job_password, password)
270
+ end
271
+ ```
272
+
273
+ ## Go deeper
225
274
 
226
275
  ### Exceptions, retries, and reliability
227
276
 
@@ -255,7 +304,7 @@ When using `retry_on` with _a limited number of retries_, the final exception wi
255
304
 
256
305
  ```ruby
257
306
  # config/initializers/good_job.rb
258
- GoodJob.reperform_jobs_on_standard_error = false
307
+ GoodJob.retry_on_unhandled_error = false
259
308
  ```
260
309
 
261
310
  Alternatively, pass a block to `retry_on` to handle the final exception instead of raising it to GoodJob:
@@ -291,16 +340,16 @@ end
291
340
 
292
341
  #### ActionMailer retries
293
342
 
294
- Any configuration in `ApplicationJob` will have to be duplicated on `ActionMailer::DeliveryJob` because ActionMailer uses a custom class, `ActionMailer::DeliveryJob`, which inherits from `ActiveJob::Base`, rather than your applications `ApplicationJob`.
343
+ Any configuration in `ApplicationJob` will have to be duplicated on `ActionMailer::MailDeliveryJob` (`ActionMailer::DeliveryJob` in Rails 5.2 or earlier) because ActionMailer uses a custom class, `ActionMailer::MailDeliveryJob`, which inherits from `ActiveJob::Base`, rather than your applications `ApplicationJob`.
295
344
 
296
- You can use an initializer to configure `ActionMailer::DeliveryJob`, for example:
345
+ You can use an initializer to configure `ActionMailer::MailDeliveryJob`, for example:
297
346
 
298
347
  ```ruby
299
348
  # config/initializers/good_job.rb
300
- ActionMailer::DeliveryJob.retry_on StandardError, wait: :exponentially_longer, attempts: Float::INFINITY
349
+ ActionMailer::MailDeliveryJob.retry_on StandardError, wait: :exponentially_longer, attempts: Float::INFINITY
301
350
 
302
351
  # With Sentry (or Bugsnag, Airbrake, Honeybadger, etc.)
303
- ActionMailer::DeliveryJob.around_perform do |_job, block|
352
+ ActionMailer::MailDeliveryJob.around_perform do |_job, block|
304
353
  block.call
305
354
  rescue StandardError => e
306
355
  Raven.capture_exception(e)
@@ -308,6 +357,9 @@ rescue StandardError => e
308
357
  end
309
358
  ```
310
359
 
360
+ Note, that `ActionMailer::MailDeliveryJob` is a default since Rails 6.0. Be sure that your app is using that class, as it
361
+ might also be configured to use (deprecated now) `ActionMailer::DeliveryJob`.
362
+
311
363
  ### Timeouts
312
364
 
313
365
  Job timeouts can be configured with an `around_perform`:
@@ -332,7 +384,7 @@ By default, GoodJob creates a single thread execution pool that will execute job
332
384
  - Multiple execution pools within a single process:
333
385
 
334
386
  ```bash
335
- $ bundle exec good_job --queues=transactional_messages:2;batch_processing:1;-transactional_messages,batch_processing:2;* --max-threads=5
387
+ $ bundle exec good_job --queues="transactional_messages:2;batch_processing:1;-transactional_messages,batch_processing:2;*" --max-threads=5
336
388
  ```
337
389
 
338
390
  This configuration will result in a single process with 4 isolated thread execution pools. Isolated execution pools are separated with a semicolon (`;`) and queue names and thread counts with a colon (`:`)
@@ -357,11 +409,11 @@ By default, GoodJob creates a single thread execution pool that will execute job
357
409
 
358
410
  # Separate dyno types
359
411
  worker: bundle exec good_job --max-threads=5
360
- transactional_worker: bundle exec good_job --queues=transactional_messages --max-threads=2
361
- batch_worker: bundle exec good_job --queues=batch_processing --max-threads=1
412
+ transactional_worker: bundle exec good_job --queues="transactional_messages" --max-threads=2
413
+ batch_worker: bundle exec good_job --queues="batch_processing" --max-threads=1
362
414
 
363
415
  # Combined multi-process dyno
364
- combined_worker: bundle exec good_job --max-threads=5 & bundle exec good_job --queues=transactional_messages --max-threads=2 & bundle exec good_job --queues=batch_processing --max-threads=1 & wait -n
416
+ combined_worker: bundle exec good_job --max-threads=5 & bundle exec good_job --queues="transactional_messages" --max-threads=2 & bundle exec good_job --queues="batch_processing" --max-threads=1 & wait -n
365
417
  ```
366
418
 
367
419
  Running multiple processes can optimize for CPU performance at the expense of greater memory and system resource usage.
@@ -377,7 +429,7 @@ Each GoodJob execution thread requires its own database connection that is autom
377
429
  pool: <%= [ENV.fetch("RAILS_MAX_THREADS", 5).to_i, ENV.fetch("GOOD_JOB_MAX_THREADS", 4).to_i].max %>
378
430
  ```
379
431
 
380
- ### Executing jobs async / in-process
432
+ ### Execute jobs async / in-process
381
433
 
382
434
  GoodJob can execute jobs "async" in the same process as the webserver (e.g. `bin/rail s`). GoodJob's async execution mode offers benefits of economy by not requiring a separate job worker process, but with the tradeoff of increased complexity. Async mode can be configured in two ways:
383
435
 
@@ -428,7 +480,7 @@ Depending on your application configuration, you may need to take additional ste
428
480
 
429
481
  GoodJob is compatible with Puma's `preload_app!` method.
430
482
 
431
- ### Migrating to GoodJob from a different ActiveJob backend
483
+ ### Migrate to GoodJob from a different ActiveJob backend
432
484
 
433
485
  If your application is already using an ActiveJob backend, you will need to install GoodJob to enqueue and perform newly created jobs _and_ finish performing pre-existing jobs on the previous backend.
434
486
 
@@ -452,7 +504,7 @@ If your application is already using an ActiveJob backend, you will need to inst
452
504
 
453
505
  1. Once you are confident that no unperformed jobs remain in the previous ActiveJob backend, code and configuration for that backend can be completely removed.
454
506
 
455
- ### Monitoring and preserving worked jobs
507
+ ### Monitor and preserve worked jobs
456
508
 
457
509
  GoodJob is fully instrumented with [`ActiveSupport::Notifications`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#introduction-to-instrumentation).
458
510
 
@@ -479,7 +531,7 @@ It is also necessary to delete these preserved jobs from the database after a ce
479
531
  $ bundle exec good_job cleanup_preserved_jobs --before-seconds-ago=86400
480
532
  ```
481
533
 
482
- ## Contributing
534
+ ## Contribute
483
535
 
484
536
  Contributions are welcomed and appreciated 🙏
485
537
 
@@ -524,7 +576,7 @@ $ bundle install
524
576
  # => Using good_job 0.1.0 from https://github.com/bensheldon/good_job.git (at /Users/You/Projects/good_job@dc57fb0)
525
577
  ```
526
578
 
527
- ### Releasing
579
+ ### Release
528
580
 
529
581
  Package maintainers can release this gem by running:
530
582
 
@@ -0,0 +1,8 @@
1
+ module GoodJob
2
+ class ActiveJobsController < GoodJob::BaseController
3
+ def show
4
+ @jobs = GoodJob::Job.where("serialized_params ->> 'job_id' = ?", params[:id])
5
+ .order('COALESCE(scheduled_at, created_at) DESC')
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module GoodJob
2
+ class BaseController < ActionController::Base # rubocop:disable Rails/ApplicationController
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ module GoodJob
2
+ class DashboardsController < GoodJob::BaseController
3
+ def index
4
+ @jobs = GoodJob::Job.display_all(after_scheduled_at: params[:after_scheduled_at], after_id: params[:after_id])
5
+ .limit(params.fetch(:limit, 10))
6
+
7
+ job_data = GoodJob::Job.connection.exec_query Arel.sql(<<~SQL.squish)
8
+ SELECT *
9
+ FROM generate_series(
10
+ date_trunc('hour', NOW() - '1 day'::interval),
11
+ date_trunc('hour', NOW()),
12
+ '1 hour'
13
+ ) timestamp
14
+ LEFT JOIN (
15
+ SELECT
16
+ date_trunc('hour', scheduled_at) AS scheduled_at,
17
+ queue_name,
18
+ count(*) AS count
19
+ FROM (
20
+ SELECT
21
+ COALESCE(scheduled_at, created_at)::timestamp AS scheduled_at,
22
+ queue_name
23
+ FROM good_jobs
24
+ ) sources
25
+ GROUP BY date_trunc('hour', scheduled_at), queue_name
26
+ ) sources ON sources.scheduled_at = timestamp
27
+ ORDER BY timestamp DESC
28
+ SQL
29
+
30
+ queue_names = job_data.map { |d| d['queue_name'] }.uniq
31
+ labels = []
32
+ queues_data = job_data.to_a.group_by { |d| d['timestamp'] }.each_with_object({}) do |(timestamp, values), hash|
33
+ labels << timestamp
34
+ queue_names.each do |queue_name|
35
+ (hash[queue_name] ||= []) << values.find { |d| d['queue_name'] == queue_name }&.[]('count')
36
+ end
37
+ end
38
+
39
+ @chart = {
40
+ labels: labels,
41
+ series: queues_data.map do |queue, data|
42
+ {
43
+ name: queue,
44
+ data: data,
45
+ }
46
+ end,
47
+ }
48
+ end
49
+ end
50
+ end