good_job 0.7.0 → 0.8.0
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 +3 -2
- data/README.md +32 -17
- data/lib/active_job/queue_adapters/good_job_adapter.rb +12 -6
- data/lib/good_job/adapter.rb +25 -5
- 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: ef13e088aa2f4e0d6671b796d01f9cf48588e4f5635c2600d6df922a7410bb63
|
4
|
+
data.tar.gz: 24773e7ab09699a3a4d0b88d87765e1bdeb4e1520410841bdd945ee7ee0b65c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02c14e07112294876b8d10cf1f2d3cd2c3a3de6eafdc23b77b913d48bd1a71bf8545b6b839871f3effd1cacac85c09cd2541d85d24f2c56a87251e55a1eef920
|
7
|
+
data.tar.gz: f51f8f509392bb432d47ff251877e8cacd1a5244099c6b9a556e4340c08e374d10138ec94239da973c575d548539467a11a2070c5166602165d37484e289a167
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [v0.
|
3
|
+
## [v0.8.0](https://github.com/bensheldon/good_job/tree/v0.8.0) (2020-07-17)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/bensheldon/good_job/compare/v0.6.0...v0.
|
5
|
+
[Full Changelog](https://github.com/bensheldon/good_job/compare/v0.6.0...v0.8.0)
|
6
6
|
|
7
7
|
**Closed issues:**
|
8
8
|
|
@@ -10,6 +10,7 @@
|
|
10
10
|
|
11
11
|
**Merged pull requests:**
|
12
12
|
|
13
|
+
- Replace Adapter inline boolean kwarg with execution\_mode instead [\#41](https://github.com/bensheldon/good_job/pull/41) ([bensheldon](https://github.com/bensheldon))
|
13
14
|
- Add more examples to Readme [\#39](https://github.com/bensheldon/good_job/pull/39) ([bensheldon](https://github.com/bensheldon))
|
14
15
|
- Add additional Rubocops and lint [\#38](https://github.com/bensheldon/good_job/pull/38) ([bensheldon](https://github.com/bensheldon))
|
15
16
|
- Always store a default queue\_name, priority and scheduled\_at; index by queue\_name and scheduled\_at [\#37](https://github.com/bensheldon/good_job/pull/37) ([bensheldon](https://github.com/bensheldon))
|
data/README.md
CHANGED
@@ -1,21 +1,13 @@
|
|
1
1
|
# GoodJob
|
2
2
|
|
3
|
-
GoodJob is a multithreaded, Postgres-based ActiveJob backend for Ruby on Rails.
|
3
|
+
GoodJob is a multithreaded, Postgres-based, ActiveJob backend for Ruby on Rails.
|
4
4
|
|
5
|
-
Inspired by [Delayed::Job](https://github.com/collectiveidea/delayed_job) and [Que](https://github.com/que-rb/que), GoodJob
|
5
|
+
**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.**
|
6
6
|
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
|
12
|
-
GoodJob supports all ActiveJob functionality:
|
13
|
-
- Async. GoodJob has the ability to run the job in a non-blocking manner.
|
14
|
-
- Queues. Jobs may set which queue they are run in with queue_as or by using the set method.
|
15
|
-
- Delayed. GoodJob will run the job in the future through perform_later.
|
16
|
-
- Priorities. The order in which jobs are processed can be configured differently.
|
17
|
-
- Timeouts. GoodJob defers to ActiveJob where it can be implemented as an `around` hook. See [Taking advantage of ActiveJob](#taking-advantage-of-activejob).
|
18
|
-
- Retries. GoodJob will automatically retry uncompleted jobs immediately. See [Taking advantage of ActiveJob](#taking-advantage-of-activejob).
|
7
|
+
- **Designed for ActiveJob.** Complete support for [async, queues, delays, priorities, timeouts, and retries](https://edgeguides.rubyonrails.org/active_job_basics.html) with near-zero configuration.
|
8
|
+
- **Built for Rails.** Fully adopts Ruby on Rails [threading and code execution guidelines](https://guides.rubyonrails.org/threading_and_code_execution.html) with [Concurrent::Ruby](https://github.com/ruby-concurrency/concurrent-ruby).
|
9
|
+
- **Backed by Postgres.** Relies upon Postgres integrity and session-level Advisory Locks to provide run-once safety and stay within the limits of `schema.rb`.
|
10
|
+
- **For most workloads.** Targets full-stack teams, economy-minded solo developers, and applications that enqueue less than 1-million jobs/day.
|
19
11
|
|
20
12
|
## Installation
|
21
13
|
|
@@ -75,13 +67,13 @@ $ bundle install
|
|
75
67
|
|
76
68
|
```ruby
|
77
69
|
# config/environments/development.rb
|
78
|
-
config.active_job.queue_adapter = GoodJob::Adapter.new(
|
70
|
+
config.active_job.queue_adapter = GoodJob::Adapter.new(execution_mode: :inline)
|
79
71
|
|
80
72
|
# config/environments/test.rb
|
81
|
-
config.active_job.queue_adapter = GoodJob::Adapter.new(
|
73
|
+
config.active_job.queue_adapter = GoodJob::Adapter.new(execution_mode: :inline)
|
82
74
|
|
83
75
|
# config/environments/production.rb
|
84
|
-
config.active_job.queue_adapter = GoodJob::Adapter.new
|
76
|
+
config.active_job.queue_adapter = GoodJob::Adapter.new(execution_mode: :external)
|
85
77
|
```
|
86
78
|
|
87
79
|
1. Queue your job 🎉:
|
@@ -137,6 +129,29 @@ GoodJob executes enqueued jobs using threads. There is a lot than can be said ab
|
|
137
129
|
3. `$ RAILS_MAX_THREADS=4 bundle exec good_job`
|
138
130
|
4. Implicitly via Rails's database connection pool size (`ActiveRecord::Base.connection_pool.size`)
|
139
131
|
|
132
|
+
### Migrating to GoodJob from a different ActiveJob backend
|
133
|
+
|
134
|
+
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.
|
135
|
+
|
136
|
+
1. Enqueue newly created jobs on GoodJob either entirely by setting `ActiveJob::Base.queue_adapter = :good_job` or progressively via individual job classes:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
# jobs/specific_job.rb
|
140
|
+
class SpecificJob < ApplicationJob
|
141
|
+
self.queue_adapter = :good_job
|
142
|
+
# ...
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
1. Continue running executors for both backends. For example, on Heroku it's possible to run [two processes](https://help.heroku.com/CTFS2TJK/how-do-i-run-multiple-processes-on-a-dyno) within the same dyno:
|
147
|
+
```procfile
|
148
|
+
# Procfile
|
149
|
+
# ...
|
150
|
+
worker: bundle exec que ./config/environment.rb & bundle exec good_job & wait -n
|
151
|
+
```
|
152
|
+
|
153
|
+
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.
|
154
|
+
|
140
155
|
## Development
|
141
156
|
|
142
157
|
To run tests:
|
@@ -1,12 +1,18 @@
|
|
1
1
|
module ActiveJob
|
2
2
|
module QueueAdapters
|
3
3
|
class GoodJobAdapter < GoodJob::Adapter
|
4
|
-
def initialize
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
def initialize(execution_mode: nil)
|
5
|
+
execution_mode = if execution_mode
|
6
|
+
execution_mode
|
7
|
+
elsif ENV['GOOD_JOB_EXECUTION_MODE'].present?
|
8
|
+
ENV['GOOD_JOB_EXECUTION_MODE'].to_sym
|
9
|
+
elsif Rails.env.development? || Rails.env.test?
|
10
|
+
:inline
|
11
|
+
else
|
12
|
+
:external
|
13
|
+
end
|
14
|
+
|
15
|
+
super(execution_mode: execution_mode)
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
data/lib/good_job/adapter.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
module GoodJob
|
2
2
|
class Adapter
|
3
|
-
|
4
|
-
|
3
|
+
EXECUTION_MODES = [:inline, :external].freeze # TODO: async
|
4
|
+
|
5
|
+
def initialize(execution_mode: nil, inline: false)
|
6
|
+
if inline
|
7
|
+
ActiveSupport::Deprecation.warn('GoodJob::Adapter#new(inline: true) is deprecated; use GoodJob::Adapter.new(execution_mode: :inline) instead')
|
8
|
+
@execution_mode = :inline
|
9
|
+
elsif execution_mode
|
10
|
+
raise ArgumentError, "execution_mode: must be one of #{EXECUTION_MODES.join(', ')}." unless EXECUTION_MODES.include?(execution_mode)
|
11
|
+
|
12
|
+
@execution_mode = execution_mode
|
13
|
+
else
|
14
|
+
@execution_mode = :external
|
15
|
+
end
|
5
16
|
end
|
6
17
|
|
7
18
|
def enqueue(active_job)
|
@@ -12,10 +23,10 @@ module GoodJob
|
|
12
23
|
good_job = GoodJob::Job.enqueue(
|
13
24
|
active_job,
|
14
25
|
scheduled_at: timestamp ? Time.zone.at(timestamp) : nil,
|
15
|
-
create_with_advisory_lock:
|
26
|
+
create_with_advisory_lock: execute_inline?
|
16
27
|
)
|
17
28
|
|
18
|
-
if
|
29
|
+
if execute_inline?
|
19
30
|
begin
|
20
31
|
good_job.perform
|
21
32
|
ensure
|
@@ -30,8 +41,17 @@ module GoodJob
|
|
30
41
|
nil
|
31
42
|
end
|
32
43
|
|
44
|
+
def execute_inline?
|
45
|
+
@execution_mode == :inline
|
46
|
+
end
|
47
|
+
|
33
48
|
def inline?
|
34
|
-
|
49
|
+
ActiveSupport::Deprecation.warn('GoodJob::Adapter::inline? is deprecated; use GoodJob::Adapter::execute_inline? instead')
|
50
|
+
execute_inline?
|
51
|
+
end
|
52
|
+
|
53
|
+
def execute_externally?
|
54
|
+
@execution_mode == :external
|
35
55
|
end
|
36
56
|
end
|
37
57
|
end
|
data/lib/good_job/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: good_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Sheldon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|