delayed_job_groups_plugin 0.1.3 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +17 -16
- data/Appraisals +30 -0
- data/CHANGELOG.md +22 -2
- data/Gemfile +2 -0
- data/README.md +4 -3
- data/Rakefile +2 -0
- data/delayed_job_groups.gemspec +18 -17
- data/gemfiles/rails_4.2.gemfile +9 -0
- data/gemfiles/rails_5.0.gemfile +9 -0
- data/gemfiles/rails_5.1.gemfile +9 -0
- data/gemfiles/rails_5.2.gemfile +9 -0
- data/gemfiles/rails_6.0.gemfile +8 -0
- data/lib/delayed/job_groups/compatibility.rb +2 -2
- data/lib/delayed/job_groups/job_extensions.rb +7 -8
- data/lib/delayed/job_groups/job_group.rb +9 -17
- data/lib/delayed/job_groups/plugin.rb +13 -22
- data/lib/delayed/job_groups/version.rb +2 -2
- data/lib/delayed/job_groups/yaml_loader.rb +17 -0
- data/lib/delayed_job_groups_plugin.rb +2 -1
- data/lib/generators/delayed_job_groups_plugin/install_generator.rb +2 -2
- data/lib/generators/delayed_job_groups_plugin/templates/migration.rb +1 -1
- data/spec/db/schema.rb +2 -2
- data/spec/delayed/job_groups/job_group_spec.rb +22 -23
- data/spec/delayed/job_groups/plugin_spec.rb +133 -84
- data/spec/delayed/job_groups/yaml_loader_spec.rb +43 -0
- data/spec/spec_helper.rb +12 -12
- data/spec/support/destroyed_model.rb +3 -3
- metadata +90 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 03a9f0066659dc667431ab9ebc586c2529832d1461258dd6d426f863e5f86d01
|
4
|
+
data.tar.gz: ab1c0829e4734e8582f59b403e51ae9caa2415afa1f871a1bab630b052cbae59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c268e4005abf1659599be599224e0ed2ff67e36f81bfaea8814de515384974ebecab3d60be9b6a985305294d9bb58ebd65c23a5a4ee5fe6300a15b46b7081a0
|
7
|
+
data.tar.gz: 55ab232adbd0e6f36d2dd36d2eab69210bdae606de95eee08de87f98545b650b4e37a9bc8dcf7838a925a3d6750e2cf7690664c0f81df23933eb7cd8bfa8d1ef
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
-
|
2
|
+
sudo: false
|
3
|
+
gemfile:
|
4
|
+
- gemfiles/rails_4.2.gemfile
|
5
|
+
- gemfiles/rails_5.0.gemfile
|
6
|
+
- gemfiles/rails_5.1.gemfile
|
7
|
+
- gemfiles/rails_5.2.gemfile
|
8
|
+
- gemfiles/rails_6.0.gemfile
|
7
9
|
rvm:
|
8
|
-
-
|
9
|
-
- 2.
|
10
|
-
- 2.
|
11
|
-
|
12
|
-
-
|
10
|
+
- 2.3.8
|
11
|
+
- 2.4.5
|
12
|
+
- 2.5.3
|
13
|
+
script:
|
14
|
+
- bundle exec rspec
|
15
|
+
- bundle exec rubocop
|
13
16
|
matrix:
|
14
17
|
exclude:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
- rvm: 2.2.0
|
20
|
-
env: RAILS_VERSION="~> 3.2.21" JRUBY_OPTS="$JRUBY_OPTS --debug"
|
18
|
+
- rvm: 2.3.8
|
19
|
+
gemfile: gemfiles/rails_6.0.gemfile
|
20
|
+
- rvm: 2.4.5
|
21
|
+
gemfile: gemfiles/rails_6.0.gemfile
|
data/Appraisals
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise 'rails-4.2' do
|
4
|
+
gem 'sqlite3', '~> 1.3.6'
|
5
|
+
gem 'activerecord', '4.2.10'
|
6
|
+
gem 'activesupport', '4.2.10'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'rails-5.0' do
|
10
|
+
gem 'sqlite3', '~> 1.3.6'
|
11
|
+
gem 'activerecord', '5.0.7'
|
12
|
+
gem 'activesupport', '5.0.7'
|
13
|
+
end
|
14
|
+
|
15
|
+
appraise 'rails-5.1' do
|
16
|
+
gem 'sqlite3', '~> 1.3.6'
|
17
|
+
gem 'activerecord', '5.1.6'
|
18
|
+
gem 'activesupport', '5.1.6'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise 'rails-5.2' do
|
22
|
+
gem 'sqlite3', '~> 1.3.6'
|
23
|
+
gem 'activerecord', '5.2.1 '
|
24
|
+
gem 'activesupport', '5.2.1 '
|
25
|
+
end
|
26
|
+
|
27
|
+
appraise 'rails-6.0' do
|
28
|
+
gem 'activerecord', '6.0.3'
|
29
|
+
gem 'activesupport', '6.0.3'
|
30
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
### 0.
|
3
|
+
### 0.4.3
|
4
|
+
* Bugfix for `on_completion_job` when `failure_cancels_group` is set to false.
|
5
|
+
|
6
|
+
### 0.4.2
|
7
|
+
* Add support for Rails 6.0.
|
8
|
+
|
9
|
+
### 0.4.1
|
10
|
+
* Bugfix for `on_completion_job` and `on_cancellation_job` YAML serialization
|
11
|
+
|
12
|
+
### 0.4.0
|
13
|
+
* Drop support for Ruby 2.0, 2.1 and 2.2.
|
14
|
+
* Add support for Ruby 2.5.
|
15
|
+
* Drop support for Rails < 4.2.
|
16
|
+
* Add support for Rails 5.2
|
17
|
+
|
18
|
+
### 0.3.0
|
19
|
+
* Drop support for Ruby 1.9 and 2.0.
|
20
|
+
|
21
|
+
### 0.2.0
|
22
|
+
* Change supported delayed job version
|
23
|
+
* Clean up lifecycle management in plugin
|
4
24
|
|
5
25
|
### 0.1.3
|
6
26
|
* Change supported rails version.
|
@@ -8,5 +28,5 @@
|
|
8
28
|
### 0.1.2
|
9
29
|
* Add configuration option to allow failed jobs not to cancel a group.
|
10
30
|
|
11
|
-
### 0.1.1
|
31
|
+
### 0.1.1
|
12
32
|
* Update the run_at for all jobs in a JobGroup when it's unblocked.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -100,15 +100,16 @@ job_group.cancel
|
|
100
100
|
|
101
101
|
Configuration to allow failed jobs not to cancel the group
|
102
102
|
```ruby
|
103
|
-
# We can optionally pass options that will allow jobs to fail without cancelling the group
|
103
|
+
# We can optionally pass options that will allow jobs to fail without cancelling the group.
|
104
|
+
# This also allows the on_completion job to fire once all jobs have either succeeded or failed.
|
104
105
|
job_group = Delayed::JobGroups::JobGroup.create!(failure_cancels_group: false)
|
105
106
|
```
|
106
107
|
|
107
108
|
## Supported Platforms
|
108
109
|
|
109
110
|
* Only the Delayed Job Active Record backend is supported.
|
110
|
-
* Tested with Rails
|
111
|
-
* Tested with MRI
|
111
|
+
* Tested with Rails 4.2 through 5.2.
|
112
|
+
* Tested with MRI 2.3 through 2.5.
|
112
113
|
|
113
114
|
## Contributing
|
114
115
|
|
data/Rakefile
CHANGED
data/delayed_job_groups.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
require 'delayed/job_groups/version'
|
@@ -8,33 +10,32 @@ Gem::Specification.new do |spec|
|
|
8
10
|
spec.version = Delayed::JobGroups::VERSION
|
9
11
|
spec.authors = ['Joel Turkel', 'Randy Burkes']
|
10
12
|
spec.email = ['jturkel@salsify.com', 'rlburkes@gmail.com']
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
+
spec.description = 'Aggregates Delayed::Job jobs into groups with group level management and lifecycle callbacks'
|
14
|
+
spec.summary = 'Delayed::Job job groups plugin'
|
13
15
|
spec.homepage = 'https://github.com/salsify/delayed_job_groups_plugin'
|
14
16
|
spec.license = 'MIT'
|
15
17
|
|
16
|
-
spec.files = `git ls-files`.split(
|
18
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
19
|
spec.test_files = Dir.glob('spec/**/*')
|
18
20
|
spec.require_paths = ['lib']
|
19
21
|
|
20
|
-
spec.
|
21
|
-
|
22
|
+
spec.required_ruby_version = '>= 2.3'
|
23
|
+
|
24
|
+
spec.add_dependency 'delayed_job', '>= 4.1'
|
25
|
+
spec.add_dependency 'delayed_job_active_record', '>= 4.1'
|
22
26
|
|
23
27
|
spec.post_install_message = 'See https://github.com/salsify/delayed_job_groups_plugin#installation for upgrade/installation notes.'
|
24
28
|
|
25
|
-
spec.add_development_dependency '
|
29
|
+
spec.add_development_dependency 'appraisal'
|
30
|
+
spec.add_dependency 'activerecord', '>= 4.2', '< 6.1'
|
26
31
|
spec.add_development_dependency 'coveralls'
|
27
32
|
spec.add_development_dependency 'database_cleaner', '>= 1.2'
|
33
|
+
spec.add_development_dependency 'mime-types'
|
28
34
|
spec.add_development_dependency 'rake'
|
29
|
-
spec.add_development_dependency 'rspec', '
|
30
|
-
spec.add_development_dependency '
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
36
|
+
spec.add_development_dependency 'rspec-its'
|
37
|
+
spec.add_development_dependency 'salsify_rubocop', '0.52.1.1'
|
38
|
+
spec.add_development_dependency 'simplecov'
|
39
|
+
spec.add_development_dependency 'sqlite3'
|
31
40
|
spec.add_development_dependency 'timecop'
|
32
|
-
|
33
|
-
if RUBY_PLATFORM == 'java'
|
34
|
-
spec.add_development_dependency 'jdbc-sqlite3'
|
35
|
-
spec.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
|
36
|
-
else
|
37
|
-
spec.add_development_dependency 'sqlite3'
|
38
|
-
end
|
39
|
-
|
40
41
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/version'
|
4
4
|
require 'active_record/version'
|
@@ -8,7 +8,7 @@ module Delayed
|
|
8
8
|
module Compatibility
|
9
9
|
|
10
10
|
def self.mass_assignment_security_enabled?
|
11
|
-
|
11
|
+
defined?(::ActiveRecord::MassAssignmentSecurity)
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Delayed
|
4
4
|
module JobGroups
|
5
5
|
module JobExtensions
|
6
6
|
extend ActiveSupport::Concern
|
7
|
+
module ReadyToRunExtension
|
8
|
+
def ready_to_run(worker_name, max_run_time)
|
9
|
+
super(worker_name, max_run_time).where(blocked: false)
|
10
|
+
end
|
11
|
+
end
|
7
12
|
|
8
13
|
included do
|
9
14
|
if Delayed::JobGroups::Compatibility.mass_assignment_security_enabled?
|
@@ -13,15 +18,9 @@ module Delayed
|
|
13
18
|
belongs_to :job_group, class_name: 'Delayed::JobGroups::JobGroup'
|
14
19
|
|
15
20
|
class << self
|
16
|
-
|
17
|
-
# Patch ready_to_run to exclude blocked jobs
|
18
|
-
def ready_to_run_with_blocked_filtering(worker_name, max_run_time)
|
19
|
-
ready_to_run_without_blocked_filtering(worker_name, max_run_time).where(blocked: false)
|
20
|
-
end
|
21
|
-
alias_method_chain :ready_to_run, :blocked_filtering
|
21
|
+
prepend ReadyToRunExtension
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
24
|
def in_job_group?
|
26
25
|
job_group_id.present?
|
27
26
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'yaml_loader'
|
2
4
|
|
3
5
|
module Delayed
|
4
6
|
module JobGroups
|
@@ -11,29 +13,19 @@ module Delayed
|
|
11
13
|
:on_cancellation_job_options, :failure_cancels_group
|
12
14
|
end
|
13
15
|
|
14
|
-
serialize :on_completion_job
|
16
|
+
serialize :on_completion_job, Delayed::JobGroups::YamlLoader
|
15
17
|
serialize :on_completion_job_options, Hash
|
16
|
-
serialize :on_cancellation_job
|
18
|
+
serialize :on_cancellation_job, Delayed::JobGroups::YamlLoader
|
17
19
|
serialize :on_cancellation_job_options, Hash
|
18
20
|
|
19
21
|
validates :queueing_complete, :blocked, :failure_cancels_group, inclusion: [true, false]
|
20
22
|
|
21
|
-
|
22
|
-
has_many :active_jobs, -> { where(failed_at: nil) }, class_name: Job
|
23
|
-
else
|
24
|
-
has_many :active_jobs, class_name: Job, conditions: {failed_at: nil}
|
25
|
-
end
|
26
|
-
|
23
|
+
has_many :active_jobs, -> { where(failed_at: nil) }, class_name: '::Delayed::Job'
|
27
24
|
|
28
25
|
# Only delete dependent jobs that are unlocked so we can determine if there are in-flight jobs
|
29
26
|
# for canceled job groups
|
30
|
-
|
31
|
-
|
32
|
-
dependent: :delete_all
|
33
|
-
else
|
34
|
-
has_many :queued_jobs, class_name: Job, conditions: {failed_at: nil, locked_by: nil},
|
35
|
-
dependent: :delete_all
|
36
|
-
end
|
27
|
+
has_many :queued_jobs, -> { where(failed_at: nil, locked_by: nil) }, class_name: '::Delayed::Job',
|
28
|
+
dependent: :delete_all
|
37
29
|
|
38
30
|
def mark_queueing_complete
|
39
31
|
with_lock do
|
@@ -78,7 +70,7 @@ module Delayed
|
|
78
70
|
end
|
79
71
|
end
|
80
72
|
|
81
|
-
def self.has_pending_jobs?(job_group_ids)
|
73
|
+
def self.has_pending_jobs?(job_group_ids) # rubocop:disable Naming/PredicateName
|
82
74
|
job_group_ids = Array(job_group_ids)
|
83
75
|
return false if job_group_ids.empty?
|
84
76
|
Delayed::Job.where(job_group_id: job_group_ids, failed_at: nil).exists?
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'delayed_job'
|
4
4
|
require 'set'
|
@@ -7,21 +7,8 @@ module Delayed
|
|
7
7
|
module JobGroups
|
8
8
|
class Plugin < Delayed::Plugin
|
9
9
|
|
10
|
-
# Delayed job callbacks will be registered in a global Delayed::Lifecycle every time a
|
11
|
-
# Delayed::Worker is created. This creates problems in test runs that create
|
12
|
-
# multiple workers because we register the callbacks multiple times on the same
|
13
|
-
# global Lifecycle.
|
14
|
-
def self.callbacks(&block)
|
15
|
-
registered_lifecycles = Set.new
|
16
|
-
super do |lifecycle|
|
17
|
-
if registered_lifecycles.add?(lifecycle.object_id)
|
18
|
-
block.call(lifecycle)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
10
|
callbacks do |lifecycle|
|
24
|
-
lifecycle.before(:error) do |
|
11
|
+
lifecycle.before(:error) do |_worker, job|
|
25
12
|
# If the job group has been cancelled then don't let the job be retried
|
26
13
|
if job.in_job_group? && job_group_cancelled?(job.job_group_id)
|
27
14
|
def job.max_attempts
|
@@ -30,7 +17,7 @@ module Delayed
|
|
30
17
|
end
|
31
18
|
end
|
32
19
|
|
33
|
-
lifecycle.before(:failure) do |
|
20
|
+
lifecycle.before(:failure) do |_worker, job|
|
34
21
|
# If a job in the job group fails, then cancel the whole job group.
|
35
22
|
# Need to check that the job group is present since another
|
36
23
|
# job may have concurrently cancelled it.
|
@@ -39,17 +26,16 @@ module Delayed
|
|
39
26
|
end
|
40
27
|
end
|
41
28
|
|
42
|
-
lifecycle.after(:perform) do |
|
29
|
+
lifecycle.after(:perform) do |_worker, job|
|
43
30
|
# Make sure we only check to see if the job group is complete
|
44
|
-
# if the job succeeded
|
45
|
-
|
31
|
+
# if the job succeeded or the job has failed (maxed out retries) with failure_cancels_group
|
32
|
+
# set to false
|
33
|
+
if job.in_job_group? && (job_completed?(job) || job_acceptably_failed?(job))
|
46
34
|
JobGroup.check_for_completion(job.job_group_id)
|
47
35
|
end
|
48
36
|
end
|
49
37
|
end
|
50
38
|
|
51
|
-
private
|
52
|
-
|
53
39
|
def self.job_group_cancelled?(job_group_id)
|
54
40
|
!JobGroup.exists?(job_group_id)
|
55
41
|
end
|
@@ -59,7 +45,12 @@ module Delayed
|
|
59
45
|
# if it has completed
|
60
46
|
job.destroyed?
|
61
47
|
end
|
48
|
+
|
49
|
+
def self.job_acceptably_failed?(job)
|
50
|
+
# Job has set failed_at (retries have maxed out) and failure_cancels_group is false signaling
|
51
|
+
# that the group should complete despite failures.
|
52
|
+
job.failed_at.present? && job.job_group.present? && !job.job_group.failure_cancels_group?
|
53
|
+
end
|
62
54
|
end
|
63
55
|
end
|
64
56
|
end
|
65
|
-
|