good_job 1.0.1 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e068306c80c1080f736520219cdf27230f9684bd69fa70cff0489ce37b1ed79
4
- data.tar.gz: 8f10fb768248ca1ec1e14f44be2073f9c60069b2451c5858c571efbca84c0969
3
+ metadata.gz: f7c64e8766a52e6bbbb5e55b409bb0100e54790d6d88340893e61f930cbf8b9e
4
+ data.tar.gz: 7e89b7bf2d3aaa45cc5b07deab36f5334a61cac44c0aec06206ddbd6eb0ebc22
5
5
  SHA512:
6
- metadata.gz: 8ebe33709d71b2254fa2fc0dbc1c991df739a67ba6ee3649000bada6c4618b2d958c58372818502b57211fb4694b28b16be513227220b262da2125b6f87b61bb
7
- data.tar.gz: 40db6accac1448cef4cfff7516e68d401b25711520d479cf3af4c20f03a31526f2e084aed5dabc64adceb9b23ae75ac41ae74e25bb80a4bb80c320a31fc9fb25
6
+ metadata.gz: 944b64f713ad584b56fe386dc63aa6afc0538e498cff4fb46aec9098306b7e436a3d29cebd968157f34e62c9b1b0ce932e15967b4a631f9f04c60ca43d77f4c8
7
+ data.tar.gz: 5000ffc97bc381cb94999478c1fe90202b681d5cf87d697f4700cc60b94a7417fd67ca3f5428c4b50acb195bde7850a3a5d809e32c5baaf08ae3a58a2101624a
@@ -1,6 +1,23 @@
1
1
  # Changelog
2
2
 
3
- ## [v1.0.1](https://github.com/bensheldon/good_job/tree/v1.0.1) (2020-07-21)
3
+ ## [v1.0.2](https://github.com/bensheldon/good_job/tree/v1.0.2) (2020-07-24)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.0.1...v1.0.2)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Fix counting of available execution threads [\#58](https://github.com/bensheldon/good_job/pull/58) ([bensheldon](https://github.com/bensheldon))
10
+
11
+ **Closed issues:**
12
+
13
+ - repeating/recurring jobs [\#53](https://github.com/bensheldon/good_job/issues/53)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - Add migration generator [\#56](https://github.com/bensheldon/good_job/pull/56) ([thedanbob](https://github.com/thedanbob))
18
+ - Fix migration script in readme [\#55](https://github.com/bensheldon/good_job/pull/55) ([thedanbob](https://github.com/thedanbob))
19
+
20
+ ## [v1.0.1](https://github.com/bensheldon/good_job/tree/v1.0.1) (2020-07-22)
4
21
 
5
22
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v1.0.0...v1.0.1)
6
23
 
@@ -32,12 +49,15 @@
32
49
 
33
50
  - Run Github Action tests on PRs from forks [\#44](https://github.com/bensheldon/good_job/pull/44) ([bensheldon](https://github.com/bensheldon))
34
51
  - Fix Rubygems homepage URL [\#43](https://github.com/bensheldon/good_job/pull/43) ([joshmn](https://github.com/joshmn))
35
- - Move where\(scheduled\_at: Time.current\) into dynamic part of GoodJob::Job::Performer [\#42](https://github.com/bensheldon/good_job/pull/42) ([bensheldon](https://github.com/bensheldon))
36
52
 
37
53
  ## [v0.8.1](https://github.com/bensheldon/good_job/tree/v0.8.1) (2020-07-18)
38
54
 
39
55
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v0.8.0...v0.8.1)
40
56
 
57
+ **Merged pull requests:**
58
+
59
+ - Move where\(scheduled\_at: Time.current\) into dynamic part of GoodJob::Job::Performer [\#42](https://github.com/bensheldon/good_job/pull/42) ([bensheldon](https://github.com/bensheldon))
60
+
41
61
  ## [v0.8.0](https://github.com/bensheldon/good_job/tree/v0.8.0) (2020-07-17)
42
62
 
43
63
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v0.7.0...v0.8.0)
data/README.md CHANGED
@@ -9,6 +9,8 @@ GoodJob is a multithreaded, Postgres-based, ActiveJob backend for Ruby on Rails.
9
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
10
  - **For most workloads.** Targets full-stack teams, economy-minded solo developers, and applications that enqueue less than 1-million jobs/day.
11
11
 
12
+ For more of the story of GoodJob, read the [introductory blog post](https://island94.org/2020/07/introducing-goodjob-1-0).
13
+
12
14
  ## Installation
13
15
 
14
16
  Add this line to your application's Gemfile:
@@ -26,34 +28,9 @@ $ bundle install
26
28
 
27
29
  1. Create a database migration:
28
30
  ```bash
29
- $ bin/rails g migration CreateGoodJobs
31
+ $ bin/rails g good_job:install
30
32
  ```
31
33
 
32
- Add to the newly created migration file:
33
-
34
- ```ruby
35
- class CreateGoodJobs < ActiveRecord::Migration[6.0]
36
- def change
37
- enable_extension 'pgcrypto'
38
-
39
- create_table :good_jobs, id: :uuid do |t|
40
- t.timestamps
41
-
42
- t.text :queue_name
43
- t.integer :priority
44
- t.jsonb :serialized_params
45
- t.timestamp :scheduled_at
46
- t.timestamp :performed_at
47
- t.timestamp :finished_at
48
- t.text :error
49
-
50
- add_index :good_jobs, :scheduled_at, where: "(finished_at IS NULL)"
51
- add_index :good_jobs, [:queue_name, :scheduled_at], where: "(finished_at IS NULL)"
52
- end
53
- end
54
- end
55
- ```
56
-
57
34
  Run the migration:
58
35
 
59
36
  ```bash
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+
4
+ module GoodJob
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+
8
+ class << self
9
+ delegate :next_migration_number, to: ActiveRecord::Generators::Base
10
+ end
11
+
12
+ source_paths << File.join(File.dirname(__FILE__), "templates")
13
+
14
+ def create_migration_file
15
+ migration_template 'migration.rb.erb', 'db/migrate/create_good_jobs.rb', migration_version: migration_version
16
+ end
17
+
18
+ private
19
+
20
+ def migration_version
21
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ class CreateGoodJobs < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ enable_extension 'pgcrypto'
4
+
5
+ create_table :good_jobs, id: :uuid do |t|
6
+ t.text :queue_name
7
+ t.integer :priority
8
+ t.jsonb :serialized_params
9
+ t.timestamp :scheduled_at
10
+ t.timestamp :performed_at
11
+ t.timestamp :finished_at
12
+ t.text :error
13
+
14
+ t.timestamps
15
+ end
16
+
17
+ add_index :good_jobs, :scheduled_at, where: "(finished_at IS NULL)"
18
+ add_index :good_jobs, [:queue_name, :scheduled_at], where: "(finished_at IS NULL)"
19
+ end
20
+ end
@@ -16,18 +16,17 @@ module GoodJob
16
16
  max_threads: Concurrent.processor_count,
17
17
  auto_terminate: true,
18
18
  idletime: 60,
19
- max_queue: 0,
20
- fallback_policy: :abort, # shouldn't matter -- 0 max queue
19
+ max_queue: -1,
20
+ fallback_policy: :discard,
21
21
  }.freeze
22
22
 
23
23
  def initialize(performer, timer_options: {}, pool_options: {})
24
24
  raise ArgumentError, "Performer argument must implement #next" unless performer.respond_to?(:next)
25
25
 
26
26
  @performer = performer
27
- @pool = Concurrent::ThreadPoolExecutor.new(DEFAULT_POOL_OPTIONS.merge(pool_options))
27
+ @pool = ThreadPoolExecutor.new(DEFAULT_POOL_OPTIONS.merge(pool_options))
28
28
  @timer = Concurrent::TimerTask.new(DEFAULT_TIMER_OPTIONS.merge(timer_options)) do
29
- idle_threads = @pool.max_length - @pool.length
30
- create_thread if idle_threads.positive?
29
+ create_thread
31
30
  end
32
31
  @timer.add_observer(self, :timer_observer)
33
32
  @timer.execute
@@ -58,6 +57,8 @@ module GoodJob
58
57
  end
59
58
 
60
59
  def create_thread
60
+ return false unless @pool.ready_worker_count.positive?
61
+
61
62
  future = Concurrent::Future.new(args: [@performer], executor: @pool) do |performer|
62
63
  output = nil
63
64
  Rails.application.executor.wrap { output = performer.next }
@@ -75,5 +76,17 @@ module GoodJob
75
76
  ActiveSupport::Notifications.instrument("finished_job_task.good_job", { result: output, error: thread_error, time: time })
76
77
  create_thread if output
77
78
  end
79
+
80
+ class ThreadPoolExecutor < Concurrent::ThreadPoolExecutor
81
+ # https://github.com/ruby-concurrency/concurrent-ruby/issues/684#issuecomment-427594437
82
+ def ready_worker_count
83
+ synchronize do
84
+ workers_still_to_be_created = @max_length - @pool.length
85
+ workers_created_but_waiting = @ready.length
86
+
87
+ workers_still_to_be_created + workers_created_but_waiting
88
+ end
89
+ end
90
+ end
78
91
  end
79
92
  end
@@ -1,3 +1,3 @@
1
1
  module GoodJob
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.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: 1.0.1
4
+ version: 1.0.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: 2020-07-22 00:00:00.000000000 Z
11
+ date: 2020-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -236,6 +236,8 @@ files:
236
236
  - README.md
237
237
  - exe/good_job
238
238
  - lib/active_job/queue_adapters/good_job_adapter.rb
239
+ - lib/generators/good_job/install_generator.rb
240
+ - lib/generators/good_job/templates/migration.rb.erb
239
241
  - lib/good_job.rb
240
242
  - lib/good_job/adapter.rb
241
243
  - lib/good_job/cli.rb