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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f7dda29494df3fc05a199d6bf0efbc825a47653c3af507a0d1ceb92456d4307
4
- data.tar.gz: 881ad046bab6b17c5d532d035fddef54420639288a0a4bd8f4f07b980c1fa239
3
+ metadata.gz: ef13e088aa2f4e0d6671b796d01f9cf48588e4f5635c2600d6df922a7410bb63
4
+ data.tar.gz: 24773e7ab09699a3a4d0b88d87765e1bdeb4e1520410841bdd945ee7ee0b65c7
5
5
  SHA512:
6
- metadata.gz: c0cfc3c4d61666844a6bd7c532670e0b1be40fd6f805eff63919d3600d06933b8029f0febbc81efbf52b1f3d459317caeb522affe20dde9d3f4d7672622fd708
7
- data.tar.gz: c4c9a9fddb2108769e3672baeaeaca2f7c966ee708f95867ed57970e688debcf1ce41a3eacd65d88c0192700f1b293cd4a9ad63fee9e4af93d44934b0876120f
6
+ metadata.gz: 02c14e07112294876b8d10cf1f2d3cd2c3a3de6eafdc23b77b913d48bd1a71bf8545b6b839871f3effd1cacac85c09cd2541d85d24f2c56a87251e55a1eef920
7
+ data.tar.gz: f51f8f509392bb432d47ff251877e8cacd1a5244099c6b9a556e4340c08e374d10138ec94239da973c575d548539467a11a2070c5166602165d37484e289a167
@@ -1,8 +1,8 @@
1
1
  # Changelog
2
2
 
3
- ## [v0.7.0](https://github.com/bensheldon/good_job/tree/v0.7.0) (2020-07-15)
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.7.0)
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’s design principles are:
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
- - Stand on the shoulders of ActiveJob. For example, [exception](https://edgeguides.rubyonrails.org/active_job_basics.html#exceptions) and [retry](https://edgeguides.rubyonrails.org/active_job_basics.html#retrying-or-discarding-failed-jobs) behavior.
8
- - Stand on the shoulders of Ruby on Rails. For example, ActiveRecord ORM, connection pools, and [multithreaded support](https://guides.rubyonrails.org/threading_and_code_execution.html) with [Concurrent-Ruby](https://github.com/ruby-concurrency/concurrent-ruby).
9
- - Stand on the shoulders of Postgres. For example, Advisory Locks.
10
- - Convention over simplicity over performance.
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(inline: true)
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(inline: true)
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
- if Rails.env.development? || Rails.env.test?
6
- super(inline: true)
7
- else
8
- super(inline: false)
9
- end
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
@@ -1,7 +1,18 @@
1
1
  module GoodJob
2
2
  class Adapter
3
- def initialize(inline: false)
4
- @inline = inline
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: inline?
26
+ create_with_advisory_lock: execute_inline?
16
27
  )
17
28
 
18
- if inline?
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
- @inline
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
@@ -1,3 +1,3 @@
1
1
  module GoodJob
2
- VERSION = '0.7.0'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  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: 0.7.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-16 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby