good_job 1.2.5 → 1.2.6
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 +36 -8
- data/README.md +58 -12
- data/engine/app/views/layouts/good_job/base.html.erb +21 -10
- data/lib/good_job.rb +1 -0
- data/lib/good_job/configuration.rb +10 -3
- data/lib/good_job/job.rb +16 -22
- data/lib/good_job/log_subscriber.rb +2 -4
- data/lib/good_job/scheduler.rb +18 -23
- data/lib/good_job/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7bb8c33f26176b048399e596b7c4c5dcb10553209b9237fe6256e7af66b1ffcc
|
|
4
|
+
data.tar.gz: b401649bfe1dee5f83575e82cb2703407c2ddc367dabaabc05f41d9f79e4315d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d38c25e5f61a8d6509f323509ecd5e0fb49a31466b58a3eae47a5614b0e56f3b30a90725d8e57dc0d170a1cda635cb49850cc98d6b4c1c4033c8a65db691af8c
|
|
7
|
+
data.tar.gz: 31add663e7307890b66f89e14b5ea164c9c67252c695db50f0d761921308019fcf7874984db7f263ae67557d1538f6b25d15271ca9880190b6faf13dc29346f8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v1.2.6](https://github.com/bensheldon/good_job/tree/v1.2.6) (2020-09-29)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.2.5...v1.2.6)
|
|
6
|
+
|
|
7
|
+
**Implemented enhancements:**
|
|
8
|
+
|
|
9
|
+
- Preserve only failed jobs [\#136](https://github.com/bensheldon/good_job/issues/136)
|
|
10
|
+
- 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))
|
|
11
|
+
|
|
12
|
+
**Fixed bugs:**
|
|
13
|
+
|
|
14
|
+
- 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))
|
|
15
|
+
|
|
16
|
+
**Closed issues:**
|
|
17
|
+
|
|
18
|
+
- run-once guarantee? [\#151](https://github.com/bensheldon/good_job/issues/151)
|
|
19
|
+
|
|
20
|
+
**Merged pull requests:**
|
|
21
|
+
|
|
22
|
+
- Add info how to setup basic auth for engine [\#153](https://github.com/bensheldon/good_job/pull/153) ([morgoth](https://github.com/morgoth))
|
|
23
|
+
- Add documentation for Dashboard Rails::Engine [\#149](https://github.com/bensheldon/good_job/pull/149) ([bensheldon](https://github.com/bensheldon))
|
|
24
|
+
- Style cleanup to Job error handling [\#147](https://github.com/bensheldon/good_job/pull/147) ([bensheldon](https://github.com/bensheldon))
|
|
25
|
+
- Replace gerund titles in Readme [\#146](https://github.com/bensheldon/good_job/pull/146) ([bensheldon](https://github.com/bensheldon))
|
|
26
|
+
- 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))
|
|
27
|
+
|
|
3
28
|
## [v1.2.5](https://github.com/bensheldon/good_job/tree/v1.2.5) (2020-09-17)
|
|
4
29
|
|
|
5
30
|
[Full Changelog](https://github.com/bensheldon/good_job/compare/v1.2.4...v1.2.5)
|
|
@@ -7,10 +32,15 @@
|
|
|
7
32
|
**Implemented enhancements:**
|
|
8
33
|
|
|
9
34
|
- Use Zeitwerk for auto-loading [\#87](https://github.com/bensheldon/good_job/issues/87)
|
|
35
|
+
- 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))
|
|
10
36
|
|
|
11
37
|
**Fixed bugs:**
|
|
12
38
|
|
|
13
39
|
- `poll-interval=-1` does not disable polling as intended [\#133](https://github.com/bensheldon/good_job/issues/133)
|
|
40
|
+
- 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))
|
|
41
|
+
- Prevent jobs hanging [\#141](https://github.com/bensheldon/good_job/pull/141) ([morgoth](https://github.com/morgoth))
|
|
42
|
+
- Add explicit require\_paths to gemspec for engine [\#134](https://github.com/bensheldon/good_job/pull/134) ([bensheldon](https://github.com/bensheldon))
|
|
43
|
+
- 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))
|
|
14
44
|
|
|
15
45
|
**Closed issues:**
|
|
16
46
|
|
|
@@ -21,17 +51,12 @@
|
|
|
21
51
|
**Merged pull requests:**
|
|
22
52
|
|
|
23
53
|
- Test GoodJob against Rails HEAD [\#144](https://github.com/bensheldon/good_job/pull/144) ([bensheldon](https://github.com/bensheldon))
|
|
24
|
-
- 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))
|
|
25
54
|
- Drop Ruby 2.4 support [\#142](https://github.com/bensheldon/good_job/pull/142) ([morgoth](https://github.com/morgoth))
|
|
26
|
-
- Prevent jobs hanging [\#141](https://github.com/bensheldon/good_job/pull/141) ([morgoth](https://github.com/morgoth))
|
|
27
55
|
- Remove arguments from perform method [\#140](https://github.com/bensheldon/good_job/pull/140) ([morgoth](https://github.com/morgoth))
|
|
28
56
|
- Extract "execute" method to reduce "perform" method complexity [\#138](https://github.com/bensheldon/good_job/pull/138) ([morgoth](https://github.com/morgoth))
|
|
29
57
|
- 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))
|
|
30
|
-
- Add explicit require\_paths to gemspec for engine [\#134](https://github.com/bensheldon/good_job/pull/134) ([bensheldon](https://github.com/bensheldon))
|
|
31
|
-
- 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))
|
|
32
58
|
- Update ActionMailer Job class, to match the default [\#130](https://github.com/bensheldon/good_job/pull/130) ([morgoth](https://github.com/morgoth))
|
|
33
59
|
- Add initial Engine scaffold [\#125](https://github.com/bensheldon/good_job/pull/125) ([bensheldon](https://github.com/bensheldon))
|
|
34
|
-
- 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))
|
|
35
60
|
- Zeitwerk Loader Implementation [\#123](https://github.com/bensheldon/good_job/pull/123) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
|
36
61
|
- Update code-level documentation [\#111](https://github.com/bensheldon/good_job/pull/111) ([bensheldon](https://github.com/bensheldon))
|
|
37
62
|
|
|
@@ -42,6 +67,11 @@
|
|
|
42
67
|
**Implemented enhancements:**
|
|
43
68
|
|
|
44
69
|
- Add environment variable to mirror `cleanup\_preserved\_jobs --before-seconds-ago=SECONDS` [\#110](https://github.com/bensheldon/good_job/issues/110)
|
|
70
|
+
- Allow env variable config for cleanups [\#114](https://github.com/bensheldon/good_job/pull/114) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
|
71
|
+
|
|
72
|
+
**Fixed bugs:**
|
|
73
|
+
|
|
74
|
+
- Better table name detection for Job queries [\#119](https://github.com/bensheldon/good_job/pull/119) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
|
45
75
|
|
|
46
76
|
**Closed issues:**
|
|
47
77
|
|
|
@@ -52,9 +82,7 @@
|
|
|
52
82
|
**Merged pull requests:**
|
|
53
83
|
|
|
54
84
|
- Remove unused PgLocks class [\#120](https://github.com/bensheldon/good_job/pull/120) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
|
55
|
-
- Better table name detection for Job queries [\#119](https://github.com/bensheldon/good_job/pull/119) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
|
56
85
|
- Fix readme CommandLine option links [\#115](https://github.com/bensheldon/good_job/pull/115) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
|
57
|
-
- Allow env variable config for cleanups [\#114](https://github.com/bensheldon/good_job/pull/114) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
|
58
86
|
- Have YARD render markdown files with GFM \(Github Flavored Markdown\) [\#113](https://github.com/bensheldon/good_job/pull/113) ([bensheldon](https://github.com/bensheldon))
|
|
59
87
|
- Add markdownlint to lint readme [\#109](https://github.com/bensheldon/good_job/pull/109) ([bensheldon](https://github.com/bensheldon))
|
|
60
88
|
- Remove unused method in PgLocks [\#107](https://github.com/bensheldon/good_job/pull/107) ([gadimbaylisahil](https://github.com/gadimbaylisahil))
|
|
@@ -354,7 +382,6 @@
|
|
|
354
382
|
- Add pg gem as explicit dependency [\#13](https://github.com/bensheldon/good_job/pull/13) ([bensheldon](https://github.com/bensheldon))
|
|
355
383
|
- 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))
|
|
356
384
|
- Add Appraisal with tests for Rails 5.1, 5.2, 6.0 [\#11](https://github.com/bensheldon/good_job/pull/11) ([bensheldon](https://github.com/bensheldon))
|
|
357
|
-
- Use Rails.logger and ActiveSupport::Notifications for logging instead of puts [\#10](https://github.com/bensheldon/good_job/pull/10) ([bensheldon](https://github.com/bensheldon))
|
|
358
385
|
|
|
359
386
|
## [v0.2.0](https://github.com/bensheldon/good_job/tree/v0.2.0) (2020-03-06)
|
|
360
387
|
|
|
@@ -362,6 +389,7 @@
|
|
|
362
389
|
|
|
363
390
|
**Merged pull requests:**
|
|
364
391
|
|
|
392
|
+
- Use Rails.logger and ActiveSupport::Notifications for logging instead of puts [\#10](https://github.com/bensheldon/good_job/pull/10) ([bensheldon](https://github.com/bensheldon))
|
|
365
393
|
- Remove minitest files [\#9](https://github.com/bensheldon/good_job/pull/9) ([bensheldon](https://github.com/bensheldon))
|
|
366
394
|
- Use scheduled\_at and priority for scheduling [\#8](https://github.com/bensheldon/good_job/pull/8) ([bensheldon](https://github.com/bensheldon))
|
|
367
395
|
- Create Github Action workflow for PRs and Issues [\#7](https://github.com/bensheldon/good_job/pull/7) ([bensheldon](https://github.com/bensheldon))
|
data/README.md
CHANGED
|
@@ -33,7 +33,8 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
|
|
|
33
33
|
- [`good_job cleanup_preserved_jobs`](#good_job-cleanup_preserved_jobs)
|
|
34
34
|
- [Adapter options](#adapter-options)
|
|
35
35
|
- [Global options](#global-options)
|
|
36
|
-
- [
|
|
36
|
+
- [Dashboard](#dashboard)
|
|
37
|
+
- [Go deeper](#go-deeper)
|
|
37
38
|
- [Exceptions, retries, and reliability](#exceptions-retries-and-reliability)
|
|
38
39
|
- [Exceptions](#exceptions)
|
|
39
40
|
- [Retries](#retries)
|
|
@@ -41,12 +42,12 @@ For more of the story of GoodJob, read the [introductory blog post](https://isla
|
|
|
41
42
|
- [Timeouts](#timeouts)
|
|
42
43
|
- [Optimize queues, threads, and processes](#optimize-queues-threads-and-processes)
|
|
43
44
|
- [Database connections](#database-connections)
|
|
44
|
-
- [
|
|
45
|
-
- [
|
|
46
|
-
- [
|
|
47
|
-
- [
|
|
45
|
+
- [Execute jobs async / in-process](#execute-jobs-async--in-process)
|
|
46
|
+
- [Migrate to GoodJob from a different ActiveJob backend](#migrate-to-goodjob-from-a-different-activejob-backend)
|
|
47
|
+
- [Monitor and preserve worked jobs](#monitor-and-preserve-worked-jobs)
|
|
48
|
+
- [Contribute](#contribute)
|
|
48
49
|
- [Gem development](#gem-development)
|
|
49
|
-
- [
|
|
50
|
+
- [Release](#release)
|
|
50
51
|
- [License](#license)
|
|
51
52
|
|
|
52
53
|
## Set up
|
|
@@ -221,7 +222,52 @@ GoodJob.reperform_jobs_on_standard_error = false
|
|
|
221
222
|
GoodJob.on_thread_error = -> (exception) { Raven.capture_exception(exception) }
|
|
222
223
|
```
|
|
223
224
|
|
|
224
|
-
|
|
225
|
+
### Dashboard
|
|
226
|
+
|
|
227
|
+
_🚧 GoodJob's dashboard is a work in progress. Please contribute ideas and code on [Github](https://github.com/bensheldon/good_job/issues)._
|
|
228
|
+
|
|
229
|
+
GoodJob includes a Dashboard as a mountable `Rails::Engine`.
|
|
230
|
+
|
|
231
|
+
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.
|
|
232
|
+
|
|
233
|
+
```ruby
|
|
234
|
+
# config/application.rb
|
|
235
|
+
require_relative 'boot'
|
|
236
|
+
|
|
237
|
+
require 'rails/all'
|
|
238
|
+
require 'good_job/engine' # <= Add this line
|
|
239
|
+
# ...
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
1. Mount the engine in your `config/routes.rb` file. The following will mount it at `http://example.com/good_job`.
|
|
243
|
+
|
|
244
|
+
```ruby
|
|
245
|
+
# config/routes.rb
|
|
246
|
+
# ...
|
|
247
|
+
mount GoodJob::Engine => 'good_job'
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Because jobs can potentially contain sensitive information, you should authorize access. For example, using Devise's `authenticate` helper, that might look like:
|
|
251
|
+
|
|
252
|
+
```ruby
|
|
253
|
+
# config/routes.rb
|
|
254
|
+
# ...
|
|
255
|
+
authenticate :user, ->(user) { user.admin? } do
|
|
256
|
+
mount GoodJob::Engine => 'good_job'
|
|
257
|
+
end
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Another option is using basic auth like this:
|
|
261
|
+
|
|
262
|
+
```ruby
|
|
263
|
+
# config/initializers/good_job.rb
|
|
264
|
+
GoodJob::Engine.middleware.use(Rack::Auth::Basic) do |username, password|
|
|
265
|
+
ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.good_job_username, username) &&
|
|
266
|
+
ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.good_job_password, password)
|
|
267
|
+
end
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Go deeper
|
|
225
271
|
|
|
226
272
|
### Exceptions, retries, and reliability
|
|
227
273
|
|
|
@@ -380,7 +426,7 @@ Each GoodJob execution thread requires its own database connection that is autom
|
|
|
380
426
|
pool: <%= [ENV.fetch("RAILS_MAX_THREADS", 5).to_i, ENV.fetch("GOOD_JOB_MAX_THREADS", 4).to_i].max %>
|
|
381
427
|
```
|
|
382
428
|
|
|
383
|
-
###
|
|
429
|
+
### Execute jobs async / in-process
|
|
384
430
|
|
|
385
431
|
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:
|
|
386
432
|
|
|
@@ -431,7 +477,7 @@ Depending on your application configuration, you may need to take additional ste
|
|
|
431
477
|
|
|
432
478
|
GoodJob is compatible with Puma's `preload_app!` method.
|
|
433
479
|
|
|
434
|
-
###
|
|
480
|
+
### Migrate to GoodJob from a different ActiveJob backend
|
|
435
481
|
|
|
436
482
|
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.
|
|
437
483
|
|
|
@@ -455,7 +501,7 @@ If your application is already using an ActiveJob backend, you will need to inst
|
|
|
455
501
|
|
|
456
502
|
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.
|
|
457
503
|
|
|
458
|
-
###
|
|
504
|
+
### Monitor and preserve worked jobs
|
|
459
505
|
|
|
460
506
|
GoodJob is fully instrumented with [`ActiveSupport::Notifications`](https://edgeguides.rubyonrails.org/active_support_instrumentation.html#introduction-to-instrumentation).
|
|
461
507
|
|
|
@@ -482,7 +528,7 @@ It is also necessary to delete these preserved jobs from the database after a ce
|
|
|
482
528
|
$ bundle exec good_job cleanup_preserved_jobs --before-seconds-ago=86400
|
|
483
529
|
```
|
|
484
530
|
|
|
485
|
-
##
|
|
531
|
+
## Contribute
|
|
486
532
|
|
|
487
533
|
Contributions are welcomed and appreciated 🙏
|
|
488
534
|
|
|
@@ -527,7 +573,7 @@ $ bundle install
|
|
|
527
573
|
# => Using good_job 0.1.0 from https://github.com/bensheldon/good_job.git (at /Users/You/Projects/good_job@dc57fb0)
|
|
528
574
|
```
|
|
529
575
|
|
|
530
|
-
###
|
|
576
|
+
### Release
|
|
531
577
|
|
|
532
578
|
Package maintainers can release this gem by running:
|
|
533
579
|
|
|
@@ -27,23 +27,34 @@
|
|
|
27
27
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
28
28
|
<ul class="navbar-nav mr-auto">
|
|
29
29
|
<li class="nav-item">
|
|
30
|
-
<%= link_to
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<%= link_to "Upcoming Jobs", 'todo', class: ["nav-link", ("active" if current_page?('todo'))] %>
|
|
34
|
-
</li>
|
|
35
|
-
<li class="nav-item">
|
|
36
|
-
<%= link_to "Finished Jobs", 'todo', class: ["nav-link", ("active" if current_page?('todo'))] %>
|
|
37
|
-
</li>
|
|
38
|
-
<li class="nav-item">
|
|
39
|
-
<%= link_to "Errored Jobs", 'todo', class: ["nav-link", ("active" if current_page?('todo'))] %>
|
|
30
|
+
<%= link_to root_path, class: ["nav-link", ("active" if current_page?(root_path))] do %>
|
|
31
|
+
All jobs <span class="badge badge-secondary">More views coming soon</span>
|
|
32
|
+
<% end %>
|
|
40
33
|
</li>
|
|
34
|
+
|
|
35
|
+
<!-- Coming Soon
|
|
36
|
+
<li class="nav-item">
|
|
37
|
+
<%= link_to "Upcoming Jobs", 'todo', class: ["nav-link", ("active" if current_page?('todo'))] %>
|
|
38
|
+
</li>
|
|
39
|
+
<li class="nav-item">
|
|
40
|
+
<%= link_to "Finished Jobs", 'todo', class: ["nav-link", ("active" if current_page?('todo'))] %>
|
|
41
|
+
</li>
|
|
42
|
+
<li class="nav-item">
|
|
43
|
+
<%= link_to "Errored Jobs", 'todo', class: ["nav-link", ("active" if current_page?('todo'))] %>
|
|
44
|
+
</li>
|
|
45
|
+
-->
|
|
41
46
|
</ul>
|
|
42
47
|
</div>
|
|
43
48
|
</div>
|
|
44
49
|
</nav>
|
|
45
50
|
|
|
46
51
|
<div class="container">
|
|
52
|
+
<div class="card border-warning text-dark my-3">
|
|
53
|
+
<div class="card-body">
|
|
54
|
+
<p class="card-text">🚧 GoodJob's dashboard is a work in progress. Please contribute ideas and code on <a href="https://github.com/bensheldon/good_job/issues" target="_blank" rel="nofollow noopener noreferrer">Github</a>.</p>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
|
|
47
58
|
<%= yield %>
|
|
48
59
|
</div>
|
|
49
60
|
</body>
|
data/lib/good_job.rb
CHANGED
|
@@ -32,6 +32,7 @@ module GoodJob
|
|
|
32
32
|
# Whether to preserve job records in the database after they have finished (default: +false+).
|
|
33
33
|
# By default, GoodJob deletes job records after the job is completed successfully.
|
|
34
34
|
# If you want to preserve jobs for latter inspection, set this to +true+.
|
|
35
|
+
# If you want to preserve only jobs that finished with error for latter inspection, set this to +:on_unhandled_error+.
|
|
35
36
|
# If +true+, you will need to clean out jobs using the +good_job cleanup_preserved_jobs+ CLI command.
|
|
36
37
|
# @return [Boolean]
|
|
37
38
|
mattr_accessor :preserve_job_records, default: false
|
|
@@ -5,6 +5,13 @@ module GoodJob
|
|
|
5
5
|
# set options to get the final values for each option.
|
|
6
6
|
#
|
|
7
7
|
class Configuration
|
|
8
|
+
# Default number of threads to use per {Scheduler}
|
|
9
|
+
DEFAULT_MAX_THREADS = 5
|
|
10
|
+
# Default number of seconds between polls for jobs
|
|
11
|
+
DEFAULT_POLL_INTERVAL = 1
|
|
12
|
+
# Default number of seconds to preserve jobs for {CLI#cleanup_preserved_jobs}
|
|
13
|
+
DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO = 24 * 60 * 60
|
|
14
|
+
|
|
8
15
|
# @!attribute [r] options
|
|
9
16
|
# The options that were explicitly set when initializing +Configuration+.
|
|
10
17
|
# @return [Hash]
|
|
@@ -69,7 +76,7 @@ module GoodJob
|
|
|
69
76
|
options[:max_threads] ||
|
|
70
77
|
env['GOOD_JOB_MAX_THREADS'] ||
|
|
71
78
|
env['RAILS_MAX_THREADS'] ||
|
|
72
|
-
|
|
79
|
+
DEFAULT_MAX_THREADS
|
|
73
80
|
).to_i
|
|
74
81
|
end
|
|
75
82
|
|
|
@@ -92,7 +99,7 @@ module GoodJob
|
|
|
92
99
|
(
|
|
93
100
|
options[:poll_interval] ||
|
|
94
101
|
env['GOOD_JOB_POLL_INTERVAL'] ||
|
|
95
|
-
|
|
102
|
+
DEFAULT_POLL_INTERVAL
|
|
96
103
|
).to_i
|
|
97
104
|
end
|
|
98
105
|
|
|
@@ -100,7 +107,7 @@ module GoodJob
|
|
|
100
107
|
(
|
|
101
108
|
options[:before_seconds_ago] ||
|
|
102
109
|
env['GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO'] ||
|
|
103
|
-
|
|
110
|
+
DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO
|
|
104
111
|
).to_i
|
|
105
112
|
end
|
|
106
113
|
end
|
data/lib/good_job/job.rb
CHANGED
|
@@ -189,37 +189,31 @@ module GoodJob
|
|
|
189
189
|
self.performed_at = Time.current
|
|
190
190
|
save! if GoodJob.preserve_job_records
|
|
191
191
|
|
|
192
|
-
result,
|
|
192
|
+
result, unhandled_error = execute
|
|
193
193
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
error = nil
|
|
198
|
-
if rescued_error
|
|
199
|
-
error = rescued_error
|
|
200
|
-
elsif result.is_a?(Exception)
|
|
201
|
-
error = result
|
|
194
|
+
result_error = nil
|
|
195
|
+
if result.is_a?(Exception)
|
|
196
|
+
result_error = result
|
|
202
197
|
result = nil
|
|
203
|
-
elsif retry_or_discard_error
|
|
204
|
-
error = retry_or_discard_error
|
|
205
198
|
end
|
|
206
199
|
|
|
207
|
-
|
|
208
|
-
|
|
200
|
+
job_error = unhandled_error ||
|
|
201
|
+
result_error ||
|
|
202
|
+
GoodJob::CurrentExecution.error_on_retry ||
|
|
203
|
+
GoodJob::CurrentExecution.error_on_discard
|
|
209
204
|
|
|
210
|
-
|
|
205
|
+
self.error = "#{job_error.class}: #{job_error.message}" if job_error
|
|
206
|
+
|
|
207
|
+
if unhandled_error && GoodJob.reperform_jobs_on_standard_error
|
|
211
208
|
save!
|
|
212
|
-
|
|
209
|
+
elsif GoodJob.preserve_job_records == true || (unhandled_error && GoodJob.preserve_job_records == :on_unhandled_error)
|
|
213
210
|
self.finished_at = Time.current
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
else
|
|
218
|
-
destroy!
|
|
219
|
-
end
|
|
211
|
+
save!
|
|
212
|
+
else
|
|
213
|
+
destroy!
|
|
220
214
|
end
|
|
221
215
|
|
|
222
|
-
[result,
|
|
216
|
+
[result, job_error]
|
|
223
217
|
end
|
|
224
218
|
|
|
225
219
|
private
|
|
@@ -25,8 +25,7 @@ module GoodJob
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# @macro notification_responder
|
|
28
|
-
def
|
|
29
|
-
# FIXME: This method does not match any good_job notifications.
|
|
28
|
+
def finished_timer_task(event)
|
|
30
29
|
exception = event.payload[:error]
|
|
31
30
|
return unless exception
|
|
32
31
|
|
|
@@ -36,8 +35,7 @@ module GoodJob
|
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
# @macro notification_responder
|
|
39
|
-
def
|
|
40
|
-
# FIXME: This method does not match any good_job notifications.
|
|
38
|
+
def finished_job_task(event)
|
|
41
39
|
exception = event.payload[:error]
|
|
42
40
|
return unless exception
|
|
43
41
|
|
data/lib/good_job/scheduler.rb
CHANGED
|
@@ -14,26 +14,26 @@ module GoodJob # :nodoc:
|
|
|
14
14
|
# The scheduler maintains an instance of +Concurrent::TimerTask+, which wakes sleeping threads and causes them to check whether the performer has new work.
|
|
15
15
|
#
|
|
16
16
|
class Scheduler
|
|
17
|
-
# Defaults for instance of Concurrent::TimerTask.
|
|
18
|
-
# The timer controls how and when sleeping threads check for new work.
|
|
19
|
-
DEFAULT_TIMER_OPTIONS = {
|
|
20
|
-
execution_interval: 1,
|
|
21
|
-
timeout_interval: 1,
|
|
22
|
-
run_now: true,
|
|
23
|
-
}.freeze
|
|
24
|
-
|
|
25
17
|
# Defaults for instance of Concurrent::ThreadPoolExecutor
|
|
26
18
|
# The thread pool is where work is performed.
|
|
27
19
|
DEFAULT_POOL_OPTIONS = {
|
|
28
20
|
name: name,
|
|
29
21
|
min_threads: 0,
|
|
30
|
-
max_threads:
|
|
22
|
+
max_threads: Configuration::DEFAULT_MAX_THREADS,
|
|
31
23
|
auto_terminate: true,
|
|
32
24
|
idletime: 60,
|
|
33
25
|
max_queue: -1,
|
|
34
26
|
fallback_policy: :discard,
|
|
35
27
|
}.freeze
|
|
36
28
|
|
|
29
|
+
# Defaults for instance of Concurrent::TimerTask.
|
|
30
|
+
# The timer controls how and when sleeping threads check for new work.
|
|
31
|
+
DEFAULT_TIMER_OPTIONS = {
|
|
32
|
+
execution_interval: Configuration::DEFAULT_POLL_INTERVAL,
|
|
33
|
+
timeout_interval: 1,
|
|
34
|
+
run_now: true,
|
|
35
|
+
}.freeze
|
|
36
|
+
|
|
37
37
|
# @!attribute [r] instances
|
|
38
38
|
# @!scope class
|
|
39
39
|
# List of all instantiated Schedulers in the current process.
|
|
@@ -62,14 +62,7 @@ module GoodJob # :nodoc:
|
|
|
62
62
|
end
|
|
63
63
|
job_performer = GoodJob::Performer.new(job_query, :perform_with_advisory_lock, name: queue_string, filter: job_filter)
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
timer_options[:execution_interval] = configuration.poll_interval
|
|
67
|
-
|
|
68
|
-
pool_options = {
|
|
69
|
-
max_threads: max_threads,
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
GoodJob::Scheduler.new(job_performer, timer_options: timer_options, pool_options: pool_options)
|
|
65
|
+
GoodJob::Scheduler.new(job_performer, max_threads: max_threads, poll_interval: configuration.poll_interval)
|
|
73
66
|
end
|
|
74
67
|
|
|
75
68
|
if schedulers.size > 1
|
|
@@ -80,18 +73,20 @@ module GoodJob # :nodoc:
|
|
|
80
73
|
end
|
|
81
74
|
|
|
82
75
|
# @param performer [GoodJob::Performer]
|
|
83
|
-
# @param
|
|
84
|
-
# @param
|
|
85
|
-
def initialize(performer,
|
|
86
|
-
# TODO: Replace `timer_options` and `pool_options` with only `poll_interval` and `max_threads`
|
|
76
|
+
# @param max_threads [Numeric, nil] the number of execution threads to use
|
|
77
|
+
# @param poll_interval [Numeric, nil] the number of seconds between polls for jobs
|
|
78
|
+
def initialize(performer, max_threads: nil, poll_interval: nil)
|
|
87
79
|
raise ArgumentError, "Performer argument must implement #next" unless performer.respond_to?(:next)
|
|
88
80
|
|
|
89
81
|
self.class.instances << self
|
|
90
82
|
|
|
91
83
|
@performer = performer
|
|
92
|
-
@pool_options = DEFAULT_POOL_OPTIONS.merge(pool_options)
|
|
93
|
-
@timer_options = DEFAULT_TIMER_OPTIONS.merge(timer_options)
|
|
94
84
|
|
|
85
|
+
@timer_options = DEFAULT_TIMER_OPTIONS.dup
|
|
86
|
+
@timer_options[:execution_interval] = poll_interval if poll_interval.present?
|
|
87
|
+
|
|
88
|
+
@pool_options = DEFAULT_POOL_OPTIONS.dup
|
|
89
|
+
@pool_options[:max_threads] = max_threads if max_threads.present?
|
|
95
90
|
@pool_options[:name] = "GoodJob::Scheduler(queues=#{@performer.name} max_threads=#{@pool_options[:max_threads]} poll_interval=#{@timer_options[:execution_interval]})"
|
|
96
91
|
|
|
97
92
|
create_pools
|
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.2.
|
|
4
|
+
version: 1.2.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Sheldon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-09-
|
|
11
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activejob
|