sidekiq-group 0.1.5 → 0.1.8
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 +4 -4
- data/lib/sidekiq/group/collection.rb +39 -17
- data/lib/sidekiq/group/version.rb +1 -1
- data/lib/sidekiq/group.rb +8 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c01687c2cafb914630079a57d1924310a4627b01f3175e4eb8f926531d0d710c
|
4
|
+
data.tar.gz: ce7e0d3ff94646c2758f4b44e8a8e009bc72711b85cb1e1f06380b63a6b8b39a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28a17e1b54c0386a8a7edd0c4633cfdb92076d1bcd979cf7ec9fbd027257fb88d32950eadbacba0932d4b000748fb151cc1362040b1606ef7df8572271e90735
|
7
|
+
data.tar.gz: 30d4868239cbbab6878f7af54a045bc02d03922bf0f0490430360f0ad4eab741125753717a81c0346697541e077ee14b89e9f0218ee1fe308b1a49fe608ccd59
|
@@ -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,18 @@ module Sidekiq
|
|
23
24
|
persist('callback_options', value.to_json)
|
24
25
|
end
|
25
26
|
|
27
|
+
def initialize_total_value
|
28
|
+
persist('total', 0)
|
29
|
+
end
|
30
|
+
|
26
31
|
def add(jid)
|
27
|
-
Sidekiq
|
32
|
+
Sidekiq.logger.info "Scheduling child job #{jid} for parent #{@cid}" if Sidekiq::Group.debug
|
28
33
|
|
29
34
|
Sidekiq.redis do |r|
|
30
|
-
r.multi do
|
31
|
-
|
32
|
-
|
35
|
+
r.multi do |pipeline|
|
36
|
+
pipeline.sadd("#{@cid}-jids", jid)
|
37
|
+
pipeline.expire("#{@cid}-jids", CID_EXPIRE_TTL)
|
38
|
+
pipeline.hincrby(@cid, 'total', 1)
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
@@ -47,26 +53,42 @@ module Sidekiq
|
|
47
53
|
callback_class, callback_options = callback_data
|
48
54
|
options = JSON(callback_options)
|
49
55
|
|
50
|
-
Sidekiq
|
56
|
+
Sidekiq.logger.info "Scheduling callback job #{callback_class} with #{options}" if Sidekiq::Group.debug
|
51
57
|
Sidekiq::Group::Worker.perform_async(callback_class, options)
|
52
58
|
|
53
59
|
cleanup_redis
|
54
60
|
end
|
55
61
|
|
62
|
+
def total
|
63
|
+
return unless spawned_all_jobs?
|
64
|
+
|
65
|
+
Sidekiq.redis { |r| r.hget(@cid, 'total').to_i }
|
66
|
+
end
|
67
|
+
|
68
|
+
def processed
|
69
|
+
return unless spawned_all_jobs?
|
70
|
+
|
71
|
+
total - pending
|
72
|
+
end
|
73
|
+
|
56
74
|
private
|
57
75
|
|
58
76
|
def remove_processed(jid)
|
59
|
-
Sidekiq
|
77
|
+
Sidekiq.logger.info "Child job #{jid} completed" if Sidekiq::Group.debug
|
78
|
+
|
79
|
+
return if Sidekiq.redis { |r| r.srem("#{@cid}-jids", jid) }
|
60
80
|
|
81
|
+
Sidekiq.logger.info "Could not remove child job #{jid} from Redis" if Sidekiq::Group.debug
|
82
|
+
sleep 1
|
61
83
|
Sidekiq.redis { |r| r.srem("#{@cid}-jids", jid) }
|
62
84
|
end
|
63
85
|
|
64
86
|
def pending
|
65
|
-
Sidekiq.redis { |r| r.scard("#{@cid}-jids") }
|
87
|
+
@pending ||= Sidekiq.redis { |r| r.scard("#{@cid}-jids") }
|
66
88
|
end
|
67
89
|
|
68
90
|
def processed_all_jobs?
|
69
|
-
Sidekiq
|
91
|
+
Sidekiq.logger.info "Pending jobs: #{pending}" if Sidekiq::Group.debug
|
70
92
|
|
71
93
|
spawned_all_jobs? && pending.zero?
|
72
94
|
end
|
@@ -77,18 +99,18 @@ module Sidekiq
|
|
77
99
|
|
78
100
|
def callback_data
|
79
101
|
Sidekiq.redis do |r|
|
80
|
-
r.multi do
|
81
|
-
|
82
|
-
|
102
|
+
r.multi do |pipeline|
|
103
|
+
pipeline.hget(@cid, 'callback_class')
|
104
|
+
pipeline.hget(@cid, 'callback_options')
|
83
105
|
end
|
84
106
|
end
|
85
107
|
end
|
86
108
|
|
87
109
|
def persist(attribute, value)
|
88
110
|
Sidekiq.redis do |r|
|
89
|
-
r.multi do
|
90
|
-
|
91
|
-
|
111
|
+
r.multi do |pipeline|
|
112
|
+
pipeline.hset(@cid, attribute, value)
|
113
|
+
pipeline.expire(@cid, CID_EXPIRE_TTL)
|
92
114
|
end
|
93
115
|
end
|
94
116
|
end
|
@@ -99,9 +121,9 @@ module Sidekiq
|
|
99
121
|
|
100
122
|
def locked?
|
101
123
|
Sidekiq.redis do |r|
|
102
|
-
r.multi do
|
103
|
-
|
104
|
-
|
124
|
+
r.multi do |pipeline|
|
125
|
+
pipeline.getset("#{@cid}-finished", 1)
|
126
|
+
pipeline.expire("#{@cid}-finished", LOCK_TTL)
|
105
127
|
end.first
|
106
128
|
end
|
107
129
|
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
|
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.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matic developers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-15 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.
|
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
|