sidekiq-batch 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
2
  SHA256:
3
- metadata.gz: '0811ae31d4850eee031831062fbe1aca229d9255f28ee85641fff02f22e4ff49'
4
- data.tar.gz: d37febab0ff1087d3b3966f0beae1155246b3535f703e3bd62e9ae04fd83a553
3
+ metadata.gz: 3d45a854229157eb70e9fb9b04390e6b4958fd535cb68d6dd2e0aab84c51e4b7
4
+ data.tar.gz: b8ec67ac9cce0cafde5b70883c0a77794f0d8506b694f74fb79765dc0ae5d7f2
5
5
  SHA512:
6
- metadata.gz: dafce26855e716909db76ed31c04f31381d2ca4ab9d9d22b4d85e95b4deda62cf5438d562cce5344596172bbc912dc5995a5b5c435cceadca78004bf8db0a7b3
7
- data.tar.gz: e25c54027984ff63d2242037de20795c8e223c4b295504678aa5a4a5f339568f44e290458f1a732d25f4c692dd6b3961256525bed66c19e20b95e0de936bf3be
6
+ metadata.gz: e703eb7d37c4234269835ee009d73cafd4bb9afb11d8c818860e18e7504244db08142830eeac20d32bff96079febcb13ae130fd7e0a21eadeea6115cb5384989
7
+ data.tar.gz: e616deb4ed0f7599b9c09d1d0fd943f25131c89966ae0575b073c507053ac9012357ed07ac34456ba0f60d1a91ab7d75c337ffe6fb4e8aca6b21fe2aea2b1ea4
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "04:00"
8
+ open-pull-requests-limit: 10
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby: ["2.5", "2.6", "2.7", "3.0", "3.1", ruby-head]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ bundler-cache: true # 'bundle install' and cache gems
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: Run tests
23
+ run: bundle exec rake
@@ -0,0 +1,19 @@
1
+ name: Mark stale issues and pull requests
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "0 0 * * *"
6
+
7
+ jobs:
8
+ stale:
9
+
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/stale@v1
14
+ with:
15
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
16
+ stale-issue-message: 'Stale issue message'
17
+ stale-pr-message: 'Stale pull request message'
18
+ stale-issue-label: 'no-issue-activity'
19
+ stale-pr-label: 'no-pr-activity'
data/Gemfile CHANGED
@@ -5,5 +5,4 @@ gemspec
5
5
  group :test do
6
6
  gem "simplecov"
7
7
  gem "codeclimate-test-reporter", "~> 1.0.0"
8
- gem 'pry-byebug'
9
8
  end
@@ -39,15 +39,15 @@ module Sidekiq
39
39
  return unless parent_bid
40
40
 
41
41
  _, _, success, _, complete, pending, children, failure = Sidekiq.redis do |r|
42
- r.multi do
43
- r.sadd("BID-#{parent_bid}-success", bid)
44
- r.expire("BID-#{parent_bid}-success", Sidekiq::Batch::BID_EXPIRE_TTL)
45
- r.scard("BID-#{parent_bid}-success")
46
- r.sadd("BID-#{parent_bid}-complete", bid)
47
- r.scard("BID-#{parent_bid}-complete")
48
- r.hincrby("BID-#{parent_bid}", "pending", 0)
49
- r.hincrby("BID-#{parent_bid}", "children", 0)
50
- r.scard("BID-#{parent_bid}-failed")
42
+ r.multi do |pipeline|
43
+ pipeline.sadd("BID-#{parent_bid}-success", bid)
44
+ pipeline.expire("BID-#{parent_bid}-success", Sidekiq::Batch::BID_EXPIRE_TTL)
45
+ pipeline.scard("BID-#{parent_bid}-success")
46
+ pipeline.sadd("BID-#{parent_bid}-complete", bid)
47
+ pipeline.scard("BID-#{parent_bid}-complete")
48
+ pipeline.hincrby("BID-#{parent_bid}", "pending", 0)
49
+ pipeline.hincrby("BID-#{parent_bid}", "children", 0)
50
+ pipeline.scard("BID-#{parent_bid}-failed")
51
51
  end
52
52
  end
53
53
  # if job finished successfully and parent batch completed call parent complete callback
@@ -61,10 +61,10 @@ module Sidekiq
61
61
 
62
62
  def complete(bid, status, parent_bid)
63
63
  pending, children, success = Sidekiq.redis do |r|
64
- r.multi do
65
- r.hincrby("BID-#{bid}", "pending", 0)
66
- r.hincrby("BID-#{bid}", "children", 0)
67
- r.scard("BID-#{bid}-success")
64
+ r.multi do |pipeline|
65
+ pipeline.hincrby("BID-#{bid}", "pending", 0)
66
+ pipeline.hincrby("BID-#{bid}", "children", 0)
67
+ pipeline.scard("BID-#{bid}-success")
68
68
  end
69
69
  end
70
70
 
@@ -80,12 +80,12 @@ module Sidekiq
80
80
 
81
81
  Sidekiq.logger.debug {"Finalize parent complete bid: #{parent_bid}"}
82
82
  _, complete, pending, children, failure = Sidekiq.redis do |r|
83
- r.multi do
84
- r.sadd("BID-#{parent_bid}-complete", bid)
85
- r.scard("BID-#{parent_bid}-complete")
86
- r.hincrby("BID-#{parent_bid}", "pending", 0)
87
- r.hincrby("BID-#{parent_bid}", "children", 0)
88
- r.scard("BID-#{parent_bid}-failed")
83
+ r.multi do |pipeline|
84
+ pipeline.sadd("BID-#{parent_bid}-complete", bid)
85
+ pipeline.scard("BID-#{parent_bid}-complete")
86
+ pipeline.hincrby("BID-#{parent_bid}", "pending", 0)
87
+ pipeline.hincrby("BID-#{parent_bid}", "children", 0)
88
+ pipeline.scard("BID-#{parent_bid}-failed")
89
89
  end
90
90
  end
91
91
  if complete == children && pending == failure
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  class Batch
3
- VERSION = '0.1.6'.freeze
3
+ VERSION = '0.1.7'.freeze
4
4
  end
5
5
  end
data/lib/sidekiq/batch.rb CHANGED
@@ -42,12 +42,12 @@ module Sidekiq
42
42
  return unless %w(success complete).include?(event.to_s)
43
43
  callback_key = "#{@bidkey}-callbacks-#{event}"
44
44
  Sidekiq.redis do |r|
45
- r.multi do
46
- r.sadd(callback_key, JSON.unparse({
45
+ r.multi do |pipeline|
46
+ pipeline.sadd(callback_key, JSON.unparse({
47
47
  callback: callback,
48
48
  opts: options
49
49
  }))
50
- r.expire(callback_key, BID_EXPIRE_TTL)
50
+ pipeline.expire(callback_key, BID_EXPIRE_TTL)
51
51
  end
52
52
  end
53
53
  end
@@ -62,10 +62,10 @@ module Sidekiq
62
62
  parent_bid = Thread.current[:batch].bid if Thread.current[:batch]
63
63
 
64
64
  Sidekiq.redis do |r|
65
- r.multi do
66
- r.hset(@bidkey, "created_at", @created_at)
67
- r.hset(@bidkey, "parent_bid", parent_bid.to_s) if parent_bid
68
- r.expire(@bidkey, BID_EXPIRE_TTL)
65
+ r.multi do |pipeline|
66
+ pipeline.hset(@bidkey, "created_at", @created_at)
67
+ pipeline.hset(@bidkey, "parent_bid", parent_bid.to_s) if parent_bid
68
+ pipeline.expire(@bidkey, BID_EXPIRE_TTL)
69
69
  end
70
70
  end
71
71
 
@@ -85,19 +85,19 @@ module Sidekiq
85
85
  return [] if @ready_to_queue.size == 0
86
86
 
87
87
  Sidekiq.redis do |r|
88
- r.multi do
88
+ r.multi do |pipeline|
89
89
  if parent_bid
90
- r.hincrby("BID-#{parent_bid}", "children", 1)
91
- r.hincrby("BID-#{parent_bid}", "total", @ready_to_queue.size)
92
- r.expire("BID-#{parent_bid}", BID_EXPIRE_TTL)
90
+ pipeline.hincrby("BID-#{parent_bid}", "children", 1)
91
+ pipeline.hincrby("BID-#{parent_bid}", "total", @ready_to_queue.size)
92
+ pipeline.expire("BID-#{parent_bid}", BID_EXPIRE_TTL)
93
93
  end
94
94
 
95
- r.hincrby(@bidkey, "pending", @ready_to_queue.size)
96
- r.hincrby(@bidkey, "total", @ready_to_queue.size)
97
- r.expire(@bidkey, BID_EXPIRE_TTL)
95
+ pipeline.hincrby(@bidkey, "pending", @ready_to_queue.size)
96
+ pipeline.hincrby(@bidkey, "total", @ready_to_queue.size)
97
+ pipeline.expire(@bidkey, BID_EXPIRE_TTL)
98
98
 
99
- r.sadd(@bidkey + "-jids", @ready_to_queue)
100
- r.expire(@bidkey + "-jids", BID_EXPIRE_TTL)
99
+ pipeline.sadd(@bidkey + "-jids", @ready_to_queue)
100
+ pipeline.expire(@bidkey + "-jids", BID_EXPIRE_TTL)
101
101
  end
102
102
  end
103
103
 
@@ -138,9 +138,9 @@ module Sidekiq
138
138
 
139
139
  def persist_bid_attr(attribute, value)
140
140
  Sidekiq.redis do |r|
141
- r.multi do
142
- r.hset(@bidkey, attribute, value)
143
- r.expire(@bidkey, BID_EXPIRE_TTL)
141
+ r.multi do |pipeline|
142
+ pipeline.hset(@bidkey, attribute, value)
143
+ pipeline.expire(@bidkey, BID_EXPIRE_TTL)
144
144
  end
145
145
  end
146
146
  end
@@ -148,26 +148,26 @@ module Sidekiq
148
148
  class << self
149
149
  def process_failed_job(bid, jid)
150
150
  _, pending, failed, children, complete, parent_bid = Sidekiq.redis do |r|
151
- r.multi do
152
- r.sadd("BID-#{bid}-failed", jid)
151
+ r.multi do |pipeline|
152
+ pipeline.sadd("BID-#{bid}-failed", jid)
153
153
 
154
- r.hincrby("BID-#{bid}", "pending", 0)
155
- r.scard("BID-#{bid}-failed")
156
- r.hincrby("BID-#{bid}", "children", 0)
157
- r.scard("BID-#{bid}-complete")
158
- r.hget("BID-#{bid}", "parent_bid")
154
+ pipeline.hincrby("BID-#{bid}", "pending", 0)
155
+ pipeline.scard("BID-#{bid}-failed")
156
+ pipeline.hincrby("BID-#{bid}", "children", 0)
157
+ pipeline.scard("BID-#{bid}-complete")
158
+ pipeline.hget("BID-#{bid}", "parent_bid")
159
159
 
160
- r.expire("BID-#{bid}-failed", BID_EXPIRE_TTL)
160
+ pipeline.expire("BID-#{bid}-failed", BID_EXPIRE_TTL)
161
161
  end
162
162
  end
163
163
 
164
164
  # if the batch failed, and has a parent, update the parent to show one pending and failed job
165
165
  if parent_bid
166
166
  Sidekiq.redis do |r|
167
- r.multi do
168
- r.hincrby("BID-#{parent_bid}", "pending", 1)
169
- r.sadd("BID-#{parent_bid}-failed", jid)
170
- r.expire("BID-#{parent_bid}-failed", BID_EXPIRE_TTL)
167
+ r.multi do |pipeline|
168
+ pipeline.hincrby("BID-#{parent_bid}", "pending", 1)
169
+ pipeline.sadd("BID-#{parent_bid}-failed", jid)
170
+ pipeline.expire("BID-#{parent_bid}-failed", BID_EXPIRE_TTL)
171
171
  end
172
172
  end
173
173
  end
@@ -179,24 +179,26 @@ module Sidekiq
179
179
 
180
180
  def process_successful_job(bid, jid)
181
181
  failed, pending, children, complete, success, total, parent_bid = Sidekiq.redis do |r|
182
- r.multi do
183
- r.scard("BID-#{bid}-failed")
184
- r.hincrby("BID-#{bid}", "pending", -1)
185
- r.hincrby("BID-#{bid}", "children", 0)
186
- r.scard("BID-#{bid}-complete")
187
- r.scard("BID-#{bid}-success")
188
- r.hget("BID-#{bid}", "total")
189
- r.hget("BID-#{bid}", "parent_bid")
190
-
191
- r.srem("BID-#{bid}-failed", jid)
192
- r.srem("BID-#{bid}-jids", jid)
193
- r.expire("BID-#{bid}", BID_EXPIRE_TTL)
182
+ r.multi do |pipeline|
183
+ pipeline.scard("BID-#{bid}-failed")
184
+ pipeline.hincrby("BID-#{bid}", "pending", -1)
185
+ pipeline.hincrby("BID-#{bid}", "children", 0)
186
+ pipeline.scard("BID-#{bid}-complete")
187
+ pipeline.scard("BID-#{bid}-success")
188
+ pipeline.hget("BID-#{bid}", "total")
189
+ pipeline.hget("BID-#{bid}", "parent_bid")
190
+
191
+ pipeline.srem("BID-#{bid}-failed", jid)
192
+ pipeline.srem("BID-#{bid}-jids", jid)
193
+ pipeline.expire("BID-#{bid}", BID_EXPIRE_TTL)
194
194
  end
195
195
  end
196
196
 
197
+ all_success = pending.to_i.zero? && children == success
197
198
  # if complete or successfull call complete callback (the complete callback may then call successful)
198
- if (pending.to_i == failed.to_i && children == complete) || (pending.to_i.zero? && children == success)
199
+ if (pending.to_i == failed.to_i && children == complete) || all_success
199
200
  enqueue_callbacks(:complete, bid)
201
+ enqueue_callbacks(:success, bid) if all_success
200
202
  end
201
203
  end
202
204
 
@@ -204,13 +206,13 @@ module Sidekiq
204
206
  batch_key = "BID-#{bid}"
205
207
  callback_key = "#{batch_key}-callbacks-#{event}"
206
208
  already_processed, _, callbacks, queue, parent_bid, callback_batch = Sidekiq.redis do |r|
207
- r.multi do
208
- r.hget(batch_key, event)
209
- r.hset(batch_key, event, true)
210
- r.smembers(callback_key)
211
- r.hget(batch_key, "callback_queue")
212
- r.hget(batch_key, "parent_bid")
213
- r.hget(batch_key, "callback_batch")
209
+ r.multi do |pipeline|
210
+ pipeline.hget(batch_key, event)
211
+ pipeline.hset(batch_key, event, true)
212
+ pipeline.smembers(callback_key)
213
+ pipeline.hget(batch_key, "callback_queue")
214
+ pipeline.hget(batch_key, "parent_bid")
215
+ pipeline.hget(batch_key, "callback_batch")
214
216
  end
215
217
  end
216
218
 
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "sidekiq", ">= 3"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.12"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "bundler", "~> 2.1"
25
+ spec.add_development_dependency "rake", "~> 13.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
- spec.add_development_dependency "fakeredis", "~> 0.7.0"
27
+ spec.add_development_dependency "fakeredis", "~> 0.8.0"
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-batch
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
  - Marcin Naglik
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-05 00:00:00.000000000 Z
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.12'
33
+ version: '2.1'
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: '1.12'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
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: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.7.0
75
+ version: 0.8.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.7.0
82
+ version: 0.8.0
83
83
  description: Sidekiq Batch Jobs Implementation
84
84
  email:
85
85
  - marcin.naglik@gmail.com
@@ -87,6 +87,9 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/dependabot.yml"
91
+ - ".github/workflows/ci.yml"
92
+ - ".github/workflows/stale.yml"
90
93
  - ".gitignore"
91
94
  - ".rspec"
92
95
  - ".travis.yml"
@@ -106,7 +109,7 @@ homepage: http://github.com/breamware/sidekiq-batch
106
109
  licenses:
107
110
  - MIT
108
111
  metadata: {}
109
- post_install_message:
112
+ post_install_message:
110
113
  rdoc_options: []
111
114
  require_paths:
112
115
  - lib
@@ -121,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
124
  - !ruby/object:Gem::Version
122
125
  version: '0'
123
126
  requirements: []
124
- rubygems_version: 3.0.3
125
- signing_key:
127
+ rubygems_version: 3.3.7
128
+ signing_key:
126
129
  specification_version: 4
127
130
  summary: Sidekiq Batch Jobs
128
131
  test_files: []