sidekiq-group 0.1.6 → 0.1.9

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: 9a8adb022ba523756cfb421bd98796ec2b99173fe1359b3bf00952ab27a3442f
4
- data.tar.gz: 5a8a8c5393db492eebf711d3d24004d188ef310d27e72dc8cc6f2408017f567f
3
+ metadata.gz: a7197dfaf3c0ad54a8b27fce70680a491c4c4934639b18c881e3940ad93c5625
4
+ data.tar.gz: 86669502c2f3b4589a1a9d5fafec9769cd72953286acec9851da3e8978b5e1c9
5
5
  SHA512:
6
- metadata.gz: 6dee7e487580f3c0acb8f59015bc6ec8f19455aba125d8801575703deaa220094781b8660646c404fa3cf31a66b3eccd4d2f21d69c6a611f53fac368b7a76b78
7
- data.tar.gz: ef1ab42cbec4753ba03613916018baa771b4bbbbc6d38559a4106fe742aa4102b4acbc31e345a90e830371e9c794bdf749bd93c42179d9d3e1a9e12ddbab5eae
6
+ metadata.gz: 9fe0ebc017096adbcc291fbf3072158ba078242b930ea154dc99c55eae6eb9dfd18cd26432b54eae62d97fbd572553348776bbf049a1741178f29152665a2195
7
+ data.tar.gz: '09ee9db6fa85a00a1fe1224d9d904049d36bbf936b7757352f9ca3d72e1c7dbd4c44e7a817de2b70be2c60a568e63e4cd4c998adfd753e244f9609af94ccf708'
@@ -8,6 +8,7 @@ module Sidekiq
8
8
  LOCK_TTL = 3600
9
9
 
10
10
  attr_reader :cid, :callback_class, :callback_options
11
+ alias group_id cid
11
12
 
12
13
  def initialize(cid = nil)
13
14
  @cid = cid || SecureRandom.urlsafe_base64(16)
@@ -23,13 +24,20 @@ module Sidekiq
23
24
  persist('callback_options', value.to_json)
24
25
  end
25
26
 
26
- def add(jid)
27
- Sidekiq::Logging.logger.info "Scheduling child job #{jid} for parent #{@cid}" if Sidekiq::Group.debug
27
+ def initialize_total_value
28
+ persist('total', 0)
29
+ end
30
+
31
+ def add(jids)
32
+ jids = Array(jids)
33
+
34
+ Sidekiq.logger.info "Scheduling child job #{jids} for parent #{@cid}" if Sidekiq::Group.debug
28
35
 
29
36
  Sidekiq.redis do |r|
30
- r.multi do
31
- r.sadd("#{@cid}-jids", jid)
32
- r.expire("#{@cid}-jids", CID_EXPIRE_TTL)
37
+ r.multi do |pipeline|
38
+ pipeline.sadd("#{@cid}-jids", jids)
39
+ pipeline.expire("#{@cid}-jids", CID_EXPIRE_TTL)
40
+ pipeline.hincrby(@cid, 'total', jids.size)
33
41
  end
34
42
  end
35
43
  end
@@ -47,20 +55,32 @@ module Sidekiq
47
55
  callback_class, callback_options = callback_data
48
56
  options = JSON(callback_options)
49
57
 
50
- Sidekiq::Logging.logger.info "Scheduling callback job #{callback_class} with #{options}" if Sidekiq::Group.debug
58
+ Sidekiq.logger.info "Scheduling callback job #{callback_class} with #{options}" if Sidekiq::Group.debug
51
59
  Sidekiq::Group::Worker.perform_async(callback_class, options)
52
60
 
53
61
  cleanup_redis
54
62
  end
55
63
 
64
+ def total
65
+ return unless spawned_all_jobs?
66
+
67
+ Sidekiq.redis { |r| r.hget(@cid, 'total').to_i }
68
+ end
69
+
70
+ def processed
71
+ return unless spawned_all_jobs?
72
+
73
+ total - pending
74
+ end
75
+
56
76
  private
57
77
 
58
78
  def remove_processed(jid)
59
- Sidekiq::Logging.logger.info "Child job #{jid} completed" if Sidekiq::Group.debug
79
+ Sidekiq.logger.info "Child job #{jid} completed" if Sidekiq::Group.debug
60
80
 
61
81
  return if Sidekiq.redis { |r| r.srem("#{@cid}-jids", jid) }
62
82
 
63
- Sidekiq::Logging.logger.info "Could not remove child job #{jid} from Redis" if Sidekiq::Group.debug
83
+ Sidekiq.logger.info "Could not remove child job #{jid} from Redis" if Sidekiq::Group.debug
64
84
  sleep 1
65
85
  Sidekiq.redis { |r| r.srem("#{@cid}-jids", jid) }
66
86
  end
@@ -70,7 +90,7 @@ module Sidekiq
70
90
  end
71
91
 
72
92
  def processed_all_jobs?
73
- Sidekiq::Logging.logger.info "Pending jobs: #{pending}" if Sidekiq::Group.debug
93
+ Sidekiq.logger.info "Pending jobs: #{pending}" if Sidekiq::Group.debug
74
94
 
75
95
  spawned_all_jobs? && pending.zero?
76
96
  end
@@ -81,18 +101,18 @@ module Sidekiq
81
101
 
82
102
  def callback_data
83
103
  Sidekiq.redis do |r|
84
- r.multi do
85
- r.hget(@cid, 'callback_class')
86
- r.hget(@cid, 'callback_options')
104
+ r.multi do |pipeline|
105
+ pipeline.hget(@cid, 'callback_class')
106
+ pipeline.hget(@cid, 'callback_options')
87
107
  end
88
108
  end
89
109
  end
90
110
 
91
111
  def persist(attribute, value)
92
112
  Sidekiq.redis do |r|
93
- r.multi do
94
- r.hset(@cid, attribute, value)
95
- r.expire(@cid, CID_EXPIRE_TTL)
113
+ r.multi do |pipeline|
114
+ pipeline.hset(@cid, attribute, value)
115
+ pipeline.expire(@cid, CID_EXPIRE_TTL)
96
116
  end
97
117
  end
98
118
  end
@@ -103,9 +123,9 @@ module Sidekiq
103
123
 
104
124
  def locked?
105
125
  Sidekiq.redis do |r|
106
- r.multi do
107
- r.getset("#{@cid}-finished", 1)
108
- r.expire("#{@cid}-finished", LOCK_TTL)
126
+ r.multi do |pipeline|
127
+ pipeline.getset("#{@cid}-finished", 1)
128
+ pipeline.expire("#{@cid}-finished", LOCK_TTL)
109
129
  end.first
110
130
  end
111
131
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Group
3
- VERSION = '0.1.6'.freeze
3
+ VERSION = '0.1.9'.freeze
4
4
  end
5
5
  end
data/lib/sidekiq/group.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'sidekiq/logging'
2
1
  require 'sidekiq/group/version'
3
2
  require 'sidekiq/group/collection'
4
3
  require 'sidekiq/group/middleware'
@@ -9,6 +8,12 @@ module Sidekiq
9
8
 
10
9
  class << self
11
10
  attr_accessor :debug
11
+
12
+ def progress(group_id)
13
+ group = Sidekiq::Group::Collection.new(group_id)
14
+
15
+ { total: group.total, processed: group.processed }
16
+ end
12
17
  end
13
18
 
14
19
  def sidekiq_group(options = {})
@@ -17,6 +22,7 @@ module Sidekiq
17
22
  group = Sidekiq::Group::Collection.new
18
23
  group.callback_class = self.class.name
19
24
  group.callback_options = options
25
+ group.initialize_total_value
20
26
 
21
27
  Thread.current[:group_collection] = group
22
28
 
@@ -32,7 +38,7 @@ module Sidekiq
32
38
  end
33
39
 
34
40
  def sidekiq_logger
35
- Sidekiq::Logging.logger
41
+ Sidekiq.logger
36
42
  end
37
43
  end
38
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-group
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matic developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-07 00:00:00.000000000 Z
11
+ date: 2022-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '5.1'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '6'
36
+ version: '6.5'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '5.1'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '6'
46
+ version: '6.5'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.0.3
109
+ rubygems_version: 3.1.3
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Addon for Sidekiq that provides similar functionality to Pro version Batches