sidekiq-group 0.1.7 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb1e0ba3a53c5a009c265ceabc99fc5153be564c12ed6c30f30e13040fc304f6
4
- data.tar.gz: 1d99d5a585a6b37e0fae401cf06a6198bc47b017a1ecae620d7659d642356573
3
+ metadata.gz: c01687c2cafb914630079a57d1924310a4627b01f3175e4eb8f926531d0d710c
4
+ data.tar.gz: ce7e0d3ff94646c2758f4b44e8a8e009bc72711b85cb1e1f06380b63a6b8b39a
5
5
  SHA512:
6
- metadata.gz: 949c2e7b90cee062a5bbd4d00ad9236a77c8432fd96fc7f14006067af0c9b8862d05bb4d126d672029250fe96021c8f3769ab8a3e24d9438f7ea4600da917f81
7
- data.tar.gz: e6b7a7cc4c5d90b1bca83f510eaa47db8d63dcdf3eb2e30b8e3a7fdd5ec3c04fba907446dc01f9ddeb170d078e95791ff21c40fcfa17e1643a54e6001bfe2165
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::Logging.logger.info "Scheduling child job #{jid} for parent #{@cid}" if Sidekiq::Group.debug
32
+ Sidekiq.logger.info "Scheduling child job #{jid} for parent #{@cid}" if Sidekiq::Group.debug
28
33
 
29
34
  Sidekiq.redis do |r|
30
35
  r.multi do |pipeline|
31
36
  pipeline.sadd("#{@cid}-jids", jid)
32
37
  pipeline.expire("#{@cid}-jids", CID_EXPIRE_TTL)
38
+ pipeline.hincrby(@cid, 'total', 1)
33
39
  end
34
40
  end
35
41
  end
@@ -47,20 +53,32 @@ module Sidekiq
47
53
  callback_class, callback_options = callback_data
48
54
  options = JSON(callback_options)
49
55
 
50
- Sidekiq::Logging.logger.info "Scheduling callback job #{callback_class} with #{options}" if Sidekiq::Group.debug
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::Logging.logger.info "Child job #{jid} completed" if Sidekiq::Group.debug
77
+ Sidekiq.logger.info "Child job #{jid} completed" if Sidekiq::Group.debug
60
78
 
61
79
  return if Sidekiq.redis { |r| r.srem("#{@cid}-jids", jid) }
62
80
 
63
- Sidekiq::Logging.logger.info "Could not remove child job #{jid} from Redis" if Sidekiq::Group.debug
81
+ Sidekiq.logger.info "Could not remove child job #{jid} from Redis" if Sidekiq::Group.debug
64
82
  sleep 1
65
83
  Sidekiq.redis { |r| r.srem("#{@cid}-jids", jid) }
66
84
  end
@@ -70,7 +88,7 @@ module Sidekiq
70
88
  end
71
89
 
72
90
  def processed_all_jobs?
73
- Sidekiq::Logging.logger.info "Pending jobs: #{pending}" if Sidekiq::Group.debug
91
+ Sidekiq.logger.info "Pending jobs: #{pending}" if Sidekiq::Group.debug
74
92
 
75
93
  spawned_all_jobs? && pending.zero?
76
94
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Group
3
- VERSION = '0.1.7'.freeze
3
+ VERSION = '0.1.8'.freeze
4
4
  end
5
5
  end
data/lib/sidekiq/group.rb CHANGED
@@ -8,6 +8,12 @@ module Sidekiq
8
8
 
9
9
  class << self
10
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
11
17
  end
12
18
 
13
19
  def sidekiq_group(options = {})
@@ -16,6 +22,7 @@ module Sidekiq
16
22
  group = Sidekiq::Group::Collection.new
17
23
  group.callback_class = self.class.name
18
24
  group.callback_options = options
25
+ group.initialize_total_value
19
26
 
20
27
  Thread.current[:group_collection] = group
21
28
 
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.7
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: 2022-05-11 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport