delayed_after_commit 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fe884ac57847ecbbd9033dabd4970b30fbb7dad9
4
- data.tar.gz: 8f61fc12eb6af16f1201c5732913e3193e0e293e
2
+ SHA256:
3
+ metadata.gz: fa387ac4caca376c5dc5fdad9457718acf26bcdfe771bdd08bf41127f77150de
4
+ data.tar.gz: b50061f1bedf4f85f34d00d3cbb21491c274b7ebb3c2b021f8015c3ecc28c19f
5
5
  SHA512:
6
- metadata.gz: 75ed837ffb31ead2cddd73175c13a33e4d4b04cac4f863316f186bf9a52080e612d08d976a7e2b28bc1b4167e8f13c21389750200d61446304f358c644432b64
7
- data.tar.gz: 51d0a79822d46c85faaf1eb4f2e2d1272e509d61f4622c8178ad507d62c800e002f09701d5de89cb4244d50198ecbcd838330a44d185902870fbdb3cf032c93a
6
+ metadata.gz: 81635199e03ed5a1339234cc78d01ea2e8bab00d1b29ffa5d05e9a5512907f2583bc67daeaedfaa6415fa03f8b9caa937eae514daccaa735877e220cde17e6dc
7
+ data.tar.gz: '0239433c563e50766e37c6d038e129b99531745523d1530a6625ac4ce64c376f137c54bbea72eb1f70f79662d4ce6d939149067580e3cede4482b071619ce778'
@@ -1 +1 @@
1
- 2.3
1
+ 2.5.7
@@ -1,7 +1,12 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.3.0
4
+ - 2.5.7
5
+
6
+ install:
7
+ - gem uninstall bundler
8
+ - gem install bundler --version '2.1.4'
9
+ - bundle install
5
10
 
6
11
  sudo: false
7
12
 
@@ -13,8 +18,7 @@ matrix:
13
18
  - rvm: jruby-head
14
19
 
15
20
  gemfile:
16
- - gemfiles/rails_42.gemfile
17
- - gemfiles/rails_5.gemfile
21
+ - gemfiles/rails_6.gemfile
18
22
 
19
23
  script: 'bundle exec rake spec'
20
24
 
data/Appraisals CHANGED
@@ -1,7 +1,3 @@
1
- appraise 'rails-42' do
2
- gem 'activerecord', '4.2.0'
1
+ appraise 'rails-6' do
2
+ gem 'activerecord', '6'
3
3
  end
4
-
5
- appraise 'rails-5' do
6
- gem 'activerecord', '5'
7
- end
data/README.md CHANGED
@@ -6,7 +6,7 @@ Exactly the same as after_commit, except it puts the job onto the Sidekiq queue.
6
6
 
7
7
  Allows you to queue active record methods, after they have been created or updated.
8
8
 
9
- Requires Sidekiq, and Rails >= 4.
9
+ Requires Sidekiq, and Rails >= 6.
10
10
 
11
11
  ## Installation
12
12
 
@@ -37,13 +37,35 @@ class User < ActiveRecord::Base
37
37
  puts "Hi - I've been updated"
38
38
  end
39
39
 
40
- def hi_ive_been_updated
40
+ def hi_im_new_around_here
41
41
  puts "Hi - I've just been created"
42
42
  end
43
43
  end
44
44
 
45
45
  ```
46
46
 
47
+ ### Notes
48
+
49
+ If you want to invoke the `delayed_after_update` callback only when an attribute has changed, you must check the attribute change with `#previous_changes`. Example:
50
+
51
+ ```ruby
52
+ delayed_after_update :geolocate, if: :location_changed?
53
+ ```
54
+
55
+ won't invoke `geolocate` even if `#location` has changed.
56
+
57
+ Instead you must do something like
58
+
59
+ ```ruby
60
+ delayed_after_update :geolocate, if: :location_was_changed?
61
+
62
+ def location_was_changed?
63
+ "location".in? previous_changes
64
+ end
65
+ ```
66
+
67
+ This is necessary because the callback is run after the transaction is committed to the database.
68
+
47
69
  ## Roadmap
48
70
 
49
71
  - Allow asyncronous callbacks on destroying objects
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activerecord", '>= 4.2.0'
22
- spec.add_development_dependency "sidekiq", "> 4.1"
23
- spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_dependency "activerecord", '>= 5.2.0'
22
+ spec.add_development_dependency "sidekiq", "> 5.0"
23
+ spec.add_development_dependency "bundler", "~> 2.1"
24
24
  spec.add_development_dependency "byebug", '>= 0'
25
25
  spec.add_development_dependency "rspec", '>= 0'
26
26
  spec.add_development_dependency "sqlite3", '>= 0'
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "5"
5
+ gem "activerecord", "6"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ delayed_after_commit (0.1.6)
5
+ activerecord (>= 5.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.0.0)
11
+ activesupport (= 6.0.0)
12
+ activerecord (6.0.0)
13
+ activemodel (= 6.0.0)
14
+ activesupport (= 6.0.0)
15
+ activesupport (6.0.0)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.1, >= 2.1.8)
21
+ appraisal (2.3.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ byebug (11.1.3)
26
+ concurrent-ruby (1.1.7)
27
+ connection_pool (2.2.3)
28
+ diff-lcs (1.4.4)
29
+ i18n (1.8.5)
30
+ concurrent-ruby (~> 1.0)
31
+ minitest (5.14.2)
32
+ rack (2.2.3)
33
+ rake (10.5.0)
34
+ redis (4.2.4)
35
+ rspec (3.10.0)
36
+ rspec-core (~> 3.10.0)
37
+ rspec-expectations (~> 3.10.0)
38
+ rspec-mocks (~> 3.10.0)
39
+ rspec-core (3.10.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-expectations (3.10.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-mocks (3.10.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-support (3.10.0)
48
+ sidekiq (6.1.2)
49
+ connection_pool (>= 2.2.2)
50
+ rack (~> 2.0)
51
+ redis (>= 4.2.0)
52
+ sqlite3 (1.4.2)
53
+ thor (1.0.1)
54
+ thread_safe (0.3.6)
55
+ tzinfo (1.2.8)
56
+ thread_safe (~> 0.1)
57
+ zeitwerk (2.4.1)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ activerecord (= 6)
64
+ appraisal
65
+ bundler (~> 2.1)
66
+ byebug
67
+ delayed_after_commit!
68
+ rake (~> 10.0)
69
+ rspec
70
+ sidekiq (> 5.0)
71
+ sqlite3
72
+
73
+ BUNDLED WITH
74
+ 2.1.4
@@ -4,11 +4,22 @@ module DelayedAfterCommit
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  class_methods do
7
- def enqueue_delayed_method(method, id)
7
+ # If retry_max is set, the queued method will retry that number of times
8
+ # before finally failing. retry_count is automatically incremented with
9
+ # each run of the method.
10
+ def enqueue_delayed_method(method, id, retry_max = nil, retry_count = 0)
8
11
  # this is used as a generic method that is created to run asyncronously from within sidekiq
9
12
  # it finds the object, and runs the deferred method
10
- if obj = self.find_by_id(id)
11
- obj.send(method)
13
+ begin
14
+ if obj = self.find_by_id(id)
15
+ obj.send(method)
16
+ end
17
+ rescue => e
18
+ if retry_max.present? && retry_count < retry_max
19
+ self.delay_for(retry_count * 60, retry: false).enqueue_delayed_method(method, id, retry_max, retry_count + 1)
20
+ end
21
+
22
+ raise e
12
23
  end
13
24
  end
14
25
 
@@ -29,10 +40,15 @@ module DelayedAfterCommit
29
40
  # this creates a method that runs `enqueue_delayed_method`
30
41
  # it then adds that method to the after_commit callback
31
42
  opts = args.extract_options!
43
+ retry_max = opts.delete(:retry_max)
32
44
  method = args.first
33
45
  delayed_method_name = "delayed_after_#{opts[:on]}_#{method}"
34
46
  define_method(delayed_method_name) do |m = method|
35
- self.class.delay.enqueue_delayed_method(m, self.id)
47
+ if retry_max.present?
48
+ self.class.delay(retry: false).enqueue_delayed_method(m, self.id, retry_max)
49
+ else
50
+ self.class.delay.enqueue_delayed_method(m, self.id)
51
+ end
36
52
  end
37
53
  self.after_commit(delayed_method_name.to_sym, opts, &block)
38
54
  end
@@ -1,3 +1,3 @@
1
1
  module DelayedAfterCommit
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_after_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Rentzke
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
19
+ version: 5.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0
26
+ version: 5.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sidekiq
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.1'
33
+ version: '5.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.1'
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.12'
47
+ version: '2.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.12'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -139,16 +139,14 @@ files:
139
139
  - bin/console
140
140
  - bin/setup
141
141
  - delayed_after_commit.gemspec
142
- - gemfiles/rails_42.gemfile
143
- - gemfiles/rails_42.gemfile.lock
144
- - gemfiles/rails_5.gemfile
145
- - gemfiles/rails_5.gemfile.lock
142
+ - gemfiles/rails_6.gemfile
143
+ - gemfiles/rails_6.gemfile.lock
146
144
  - lib/delayed_after_commit.rb
147
145
  - lib/delayed_after_commit/version.rb
148
146
  homepage: https://github.com/intellum/delayed_after_commit
149
147
  licenses: []
150
148
  metadata: {}
151
- post_install_message:
149
+ post_install_message:
152
150
  rdoc_options: []
153
151
  require_paths:
154
152
  - lib
@@ -163,9 +161,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
161
  - !ruby/object:Gem::Version
164
162
  version: '0'
165
163
  requirements: []
166
- rubyforge_project:
167
- rubygems_version: 2.5.1
168
- signing_key:
164
+ rubyforge_project:
165
+ rubygems_version: 2.7.6.2
166
+ signing_key:
169
167
  specification_version: 4
170
168
  summary: delayed after commit
171
169
  test_files: []
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "4.2.0"
6
-
7
- gemspec :path => "../"
@@ -1,80 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- delayed_after_commit (0.1.0)
5
- activerecord (>= 4.2.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (4.2.0)
11
- activesupport (= 4.2.0)
12
- builder (~> 3.1)
13
- activerecord (4.2.0)
14
- activemodel (= 4.2.0)
15
- activesupport (= 4.2.0)
16
- arel (~> 6.0)
17
- activesupport (4.2.0)
18
- i18n (~> 0.7)
19
- json (~> 1.7, >= 1.7.7)
20
- minitest (~> 5.1)
21
- thread_safe (~> 0.3, >= 0.3.4)
22
- tzinfo (~> 1.1)
23
- appraisal (2.1.0)
24
- bundler
25
- rake
26
- thor (>= 0.14.0)
27
- arel (6.0.3)
28
- builder (3.2.2)
29
- byebug (9.0.6)
30
- concurrent-ruby (1.0.2)
31
- connection_pool (2.2.0)
32
- diff-lcs (1.2.5)
33
- i18n (0.7.0)
34
- json (1.8.3)
35
- minitest (5.9.1)
36
- rack (2.0.1)
37
- rack-protection (1.5.3)
38
- rack
39
- rake (10.5.0)
40
- redis (3.3.1)
41
- rspec (3.5.0)
42
- rspec-core (~> 3.5.0)
43
- rspec-expectations (~> 3.5.0)
44
- rspec-mocks (~> 3.5.0)
45
- rspec-core (3.5.4)
46
- rspec-support (~> 3.5.0)
47
- rspec-expectations (3.5.0)
48
- diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.5.0)
50
- rspec-mocks (3.5.0)
51
- diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.5.0)
53
- rspec-support (3.5.0)
54
- sidekiq (4.2.3)
55
- concurrent-ruby (~> 1.0)
56
- connection_pool (~> 2.2, >= 2.2.0)
57
- rack-protection (>= 1.5.0)
58
- redis (~> 3.2, >= 3.2.1)
59
- sqlite3 (1.3.12)
60
- thor (0.19.1)
61
- thread_safe (0.3.5)
62
- tzinfo (1.2.2)
63
- thread_safe (~> 0.1)
64
-
65
- PLATFORMS
66
- ruby
67
-
68
- DEPENDENCIES
69
- activerecord (= 4.2.0)
70
- appraisal
71
- bundler (~> 1.12)
72
- byebug
73
- delayed_after_commit!
74
- rake (~> 10.0)
75
- rspec
76
- sidekiq (> 4.1)
77
- sqlite3
78
-
79
- BUNDLED WITH
80
- 1.12.5
@@ -1,76 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- delayed_after_commit (0.1.0)
5
- activerecord (>= 4.2.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (5.0.0)
11
- activesupport (= 5.0.0)
12
- activerecord (5.0.0)
13
- activemodel (= 5.0.0)
14
- activesupport (= 5.0.0)
15
- arel (~> 7.0)
16
- activesupport (5.0.0)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (~> 0.7)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- appraisal (2.1.0)
22
- bundler
23
- rake
24
- thor (>= 0.14.0)
25
- arel (7.1.4)
26
- byebug (9.0.6)
27
- concurrent-ruby (1.0.2)
28
- connection_pool (2.2.0)
29
- diff-lcs (1.2.5)
30
- i18n (0.7.0)
31
- minitest (5.9.1)
32
- rack (2.0.1)
33
- rack-protection (1.5.3)
34
- rack
35
- rake (10.5.0)
36
- redis (3.3.1)
37
- rspec (3.5.0)
38
- rspec-core (~> 3.5.0)
39
- rspec-expectations (~> 3.5.0)
40
- rspec-mocks (~> 3.5.0)
41
- rspec-core (3.5.4)
42
- rspec-support (~> 3.5.0)
43
- rspec-expectations (3.5.0)
44
- diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.5.0)
46
- rspec-mocks (3.5.0)
47
- diff-lcs (>= 1.2.0, < 2.0)
48
- rspec-support (~> 3.5.0)
49
- rspec-support (3.5.0)
50
- sidekiq (4.2.3)
51
- concurrent-ruby (~> 1.0)
52
- connection_pool (~> 2.2, >= 2.2.0)
53
- rack-protection (>= 1.5.0)
54
- redis (~> 3.2, >= 3.2.1)
55
- sqlite3 (1.3.12)
56
- thor (0.19.1)
57
- thread_safe (0.3.5)
58
- tzinfo (1.2.2)
59
- thread_safe (~> 0.1)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord (= 5)
66
- appraisal
67
- bundler (~> 1.12)
68
- byebug
69
- delayed_after_commit!
70
- rake (~> 10.0)
71
- rspec
72
- sidekiq (> 4.1)
73
- sqlite3
74
-
75
- BUNDLED WITH
76
- 1.12.5