sidekiq-status 2.1.3 → 3.0.0

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: 73189e5075131660e13e76ce8e8eeedd84953c90998941dd73a16825dc96d951
4
- data.tar.gz: 5923bc75138cee22d8b5edcc5fbb9ad42dad4e0d89f29df74df68656a73adadc
3
+ metadata.gz: 5188215b7cc5735ac70ba8ea4fa9d62df0a2b8d317b901540bf9665bbf5b0e9a
4
+ data.tar.gz: 4db9d510d4a0908c6a6763f1b89075fa7e031779387c8c05d7940719a3da404f
5
5
  SHA512:
6
- metadata.gz: '09e500e508e3a0d309e5d817a0fb7e1f58b9013f32284608ae5e2512bd556d07e7846c240789a2df4d5790f0aa183b3623181fd14acb12fd14a863ae354f627e'
7
- data.tar.gz: 37b1eb9dec966fc8d8645c0ea4139d9a4cee715aca5c5b988881d63599d77e4d7cc564472a3f72e58923b8fb903ed0254c123821dafa2122c622e0dfc5b1e3ca
6
+ metadata.gz: de2e9e08e65532dce024e2250e641b6a25833fdf5e977c86860018225c7769538d16076c627eb2f90af1ac4b9b0e035fc347c3651bcae06af43a4e622eef147b
7
+ data.tar.gz: 3b1508b26d23b45b48692e033d78341dd65ca81f9382bd2498cee07f236b781a176c52dbb079a37409242ffd61632266d00e5c99e60d37eba434e495245117bd
@@ -0,0 +1,53 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ jobs:
12
+ test:
13
+
14
+ runs-on: ubuntu-latest
15
+
16
+ services:
17
+ redis:
18
+ image: redis
19
+ options: >-
20
+ --health-cmd "redis-cli ping"
21
+ --health-interval 10s
22
+ --health-timeout 5s
23
+ --health-retries 5
24
+ ports:
25
+ - 6379:6379
26
+
27
+ strategy:
28
+ fail-fast: false
29
+ matrix:
30
+ ruby-version:
31
+ - '2.7'
32
+ - '3.0'
33
+ - '3.1'
34
+ - '3.2'
35
+ gemfile:
36
+ - 'gemfiles/sidekiq_6.1.gemfile'
37
+ - 'gemfiles/sidekiq_6.x.gemfile'
38
+ - 'gemfiles/sidekiq_7.x.gemfile'
39
+
40
+ env:
41
+ BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
42
+
43
+ steps:
44
+ - uses: actions/checkout@v3
45
+ - name: Set up Ruby ${{ matrix.ruby-version }}
46
+ uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: ${{ matrix.ruby-version }}
49
+ bundler-cache: true
50
+ rubygems: latest
51
+ - name: Run tests
52
+ run: |
53
+ bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,26 +1,31 @@
1
+ **Version 3.0.0**
2
+ - Drops support for Sidekiq 5.x
3
+ - Adds support for Sidekiq 7.x
4
+ - Migrates from Travis CI to GitHub Actions
5
+
1
6
  **Version 2.1.3**
2
- * Fixes redis deprecation warnings (https://github.com/kenaniah/sidekiq-status/issues/11)
7
+ - Fixes redis deprecation warnings (https://github.com/kenaniah/sidekiq-status/issues/11)
3
8
 
4
9
  **Version 2.1.2**
5
- * Casts values to strings when HTML-encoding
10
+ - Casts values to strings when HTML-encoding
6
11
 
7
12
  **Version 2.1.1**
8
- * Ensures parameter outputs are properly HTML-encoded
13
+ - Ensures parameter outputs are properly HTML-encoded
9
14
 
10
15
  **Version 2.1.0**
11
- * Adds support for Sidekiq 6.2.2+ (https://github.com/mperham/sidekiq/issues/4955)
16
+ - Adds support for Sidekiq 6.2.2+ (https://github.com/mperham/sidekiq/issues/4955)
12
17
 
13
18
  **Version 2.0.2**
14
- * Fixes for dark mode theme
19
+ - Fixes for dark mode theme
15
20
 
16
21
  **Version 2.0.1**
17
- * Adds support for dark mode to the job status page
22
+ - Adds support for dark mode to the job status page
18
23
 
19
24
  **Version 2.0.0**
20
- * Adds support for Ruby 2.7, 3.0
21
- * Adds support for Sidekiq 6.x
22
- * Removes support for Ruby 2.3, 2.4, 2.5
23
- * Removes support for Sidekiq 3.x, 4.x
25
+ - Adds support for Ruby 2.7, 3.0
26
+ - Adds support for Sidekiq 6.x
27
+ - Removes support for Ruby 2.3, 2.4, 2.5
28
+ - Removes support for Sidekiq 3.x, 4.x
24
29
 
25
30
  **Versions 1.1.4 and prior**
26
31
 
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Sidekiq::Status
2
2
  [![Gem Version](https://badge.fury.io/rb/sidekiq-status.svg)](https://badge.fury.io/rb/sidekiq-status)
3
- [![Build Status](https://www.travis-ci.com/kenaniah/sidekiq-status.svg?branch=main)](https://www.travis-ci.com/github/kenaniah/sidekiq-status)
3
+ [![Build Status](https://github.com/kenaniah/sidekiq-status/actions/workflows/ci.yaml/badge.svg)](https://github.com/kenaniah/sidekiq-status/actions/)
4
4
  [![Inline docs](https://inch-ci.org/github/kenaniah/sidekiq-status.svg?branch=main)](https://inch-ci.org/github/kenaniah/sidekiq-status)
5
5
 
6
6
  Sidekiq-status is an extension to [Sidekiq](https://github.com/mperham/sidekiq) that tracks information about your Sidekiq and provides a UI to that purpose. It was inspired by [resque-status](https://github.com/quirkey/resque-status).
7
7
 
8
- Requires Ruby 2.6+ and Sidekiq 5.0+ or newer.
8
+ Requires Ruby 2.6+ and Sidekiq 6.0+ or newer.
9
9
 
10
10
  ## Installation
11
11
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "sidekiq", "~> 5"
5
+ gem "sidekiq", "~> 7"
6
6
 
7
7
  gemspec path: "../"
@@ -48,7 +48,7 @@ module Sidekiq::Status
48
48
 
49
49
  def display_args(msg, queue)
50
50
  job = JOB_CLASS.new(msg, queue)
51
- return job.display_args.to_a.empty? ? nil : job.display_args.to_json
51
+ return job.display_args.to_a.empty? ? "{}" : job.display_args.to_json
52
52
  rescue Exception => e
53
53
  # For Sidekiq ~> 2.7
54
54
  return msg['args'].to_a.empty? ? nil : msg['args'].to_json
@@ -0,0 +1,18 @@
1
+ # adapter for redis-rb client
2
+ class Sidekiq::Status::RedisAdapter
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+
7
+ def scan(**options, &block)
8
+ @client.scan_each(**options, &block)
9
+ end
10
+
11
+ def schedule_batch(key, options)
12
+ @client.zrangebyscore key, options[:start], options[:end], limit: [options[:offset], options[:limit]]
13
+ end
14
+
15
+ def method_missing(method, *args)
16
+ @client.send(method, *args)
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ # adapter for redis-client client
2
+ class Sidekiq::Status::RedisClientAdapter
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+
7
+ def schedule_batch(key, options)
8
+ @client.zrange(key, options[:start], options[:end], :byscore, :limit, options[:offset], options[:limit])
9
+ end
10
+
11
+ def method_missing(method, *args)
12
+ @client.send(method, *args)
13
+ end
14
+ end
@@ -12,6 +12,7 @@ module Sidekiq::Status::Storage
12
12
  # @param [ConnectionPool] redis_pool optional redis connection pool
13
13
  # @return [String] Redis operation status code
14
14
  def store_for_id(id, status_updates, expiration = nil, redis_pool=nil)
15
+ status_updates.transform_values!(&:to_s)
15
16
  redis_connection(redis_pool) do |conn|
16
17
  conn.multi do |pipeline|
17
18
  pipeline.hmset key(id), 'update_time', Time.now.to_i, *(status_updates.to_a.flatten(1))
@@ -36,7 +37,7 @@ module Sidekiq::Status::Storage
36
37
  # @param [String] id job id
37
38
  # @param [Num] job_unix_time, unix timestamp for the scheduled job
38
39
  def delete_and_unschedule(job_id, job_unix_time = nil)
39
- Sidekiq.redis do |conn|
40
+ Sidekiq::Status.redis_adapter do |conn|
40
41
  scan_options = {offset: 0, conn: conn, start: (job_unix_time || '-inf'), end: (job_unix_time || '+inf')}
41
42
 
42
43
  while not (jobs = schedule_batch(scan_options)).empty?
@@ -66,7 +67,7 @@ module Sidekiq::Status::Storage
66
67
  # @param [String] Symbol field fetched field name
67
68
  # @return [String] Redis operation status code
68
69
  def read_field_for_id(id, field)
69
- Sidekiq.redis do |conn|
70
+ Sidekiq::Status.redis_adapter do |conn|
70
71
  conn.hget(key(id), field)
71
72
  end
72
73
  end
@@ -75,8 +76,8 @@ module Sidekiq::Status::Storage
75
76
  # @param [String] id job id
76
77
  # @return [Hash] Hash stored in redis
77
78
  def read_hash_for_id(id)
78
- Sidekiq.redis do |conn|
79
- conn.hgetall key(id)
79
+ Sidekiq::Status.redis_adapter do |conn|
80
+ conn.hgetall(key(id))
80
81
  end
81
82
  end
82
83
 
@@ -90,7 +91,7 @@ module Sidekiq::Status::Storage
90
91
  # - end: end score (i.e. +inf or a unix timestamp)
91
92
  # - offset: current progress through (all) jobs (e.g.: 100 if you want jobs from 100 to BATCH_LIMIT)
92
93
  def schedule_batch(options)
93
- options[:conn].zrangebyscore "schedule", options[:start], options[:end], limit: [options[:offset], BATCH_LIMIT]
94
+ Sidekiq::Status.wrap_redis_connection(options[:conn]).schedule_batch("schedule", options.merge(limit: BATCH_LIMIT))
94
95
  end
95
96
 
96
97
  # Searches the jobs Array for the job_id
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Status
3
- VERSION = '2.1.3'
3
+ VERSION = '3.0.0'
4
4
  end
5
5
  end
@@ -81,8 +81,8 @@ module Sidekiq::Status
81
81
 
82
82
  app.get '/statuses' do
83
83
 
84
- jids = Sidekiq.redis do |conn|
85
- conn.scan_each(match: 'sidekiq:status:*', count: 100).map do |key|
84
+ jids = Sidekiq::Status.redis_adapter do |conn|
85
+ conn.scan(match: 'sidekiq:status:*', count: 100).map do |key|
86
86
  key.split(':').last
87
87
  end.uniq
88
88
  end
@@ -11,14 +11,14 @@ module Sidekiq::Status::Worker
11
11
  # @param [Hash] status_updates updated values
12
12
  # @return [String] Redis operation status code
13
13
  def store(hash)
14
- store_for_id @provider_job_id || @job_id || @jid, hash, @expiration
14
+ store_for_id @provider_job_id || @job_id || @jid || "", hash, @expiration
15
15
  end
16
16
 
17
17
  # Read value from job status hash
18
18
  # @param String|Symbol hask key
19
19
  # @return [String]
20
20
  def retrieve(name)
21
- read_field_for_id @provider_job_id || @job_id || @jid, name
21
+ read_field_for_id @provider_job_id || @job_id || @jid || "", name
22
22
  end
23
23
 
24
24
  # Sets current task progress
@@ -2,6 +2,8 @@ require 'sidekiq-status/version'
2
2
  require 'sidekiq-status/sidekiq_extensions'
3
3
  require 'sidekiq-status/storage'
4
4
  require 'sidekiq-status/worker'
5
+ require 'sidekiq-status/redis_client_adapter'
6
+ require 'sidekiq-status/redis_adapter'
5
7
  require 'sidekiq-status/client_middleware'
6
8
  require 'sidekiq-status/server_middleware'
7
9
  require 'sidekiq-status/web' if defined?(Sidekiq::Web)
@@ -64,5 +66,17 @@ module Sidekiq::Status
64
66
  def message(job_id)
65
67
  get(job_id, :message)
66
68
  end
69
+
70
+ def wrap_redis_connection(conn)
71
+ if Sidekiq.major_version >= 7
72
+ conn.is_a?(RedisClientAdapter) ? conn : RedisClientAdapter.new(conn)
73
+ else
74
+ conn.is_a?(RedisAdapter) ? conn : RedisAdapter.new(conn)
75
+ end
76
+ end
77
+
78
+ def redis_adapter
79
+ Sidekiq.redis { |conn| yield wrap_redis_connection(conn) }
80
+ end
67
81
  end
68
82
  end
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ['lib']
15
15
  gem.version = Sidekiq::Status::VERSION
16
16
 
17
- gem.add_dependency 'sidekiq', '>= 5.0'
17
+ gem.add_dependency 'sidekiq', '>= 6.0', '< 8'
18
18
  gem.add_dependency 'chronic_duration'
19
19
  gem.add_development_dependency 'appraisal'
20
20
  gem.add_development_dependency 'colorize'
@@ -9,8 +9,9 @@ describe Sidekiq::Status::ServerMiddleware do
9
9
  it "sets working/complete status" do
10
10
  allow(SecureRandom).to receive(:hex).once.and_return(job_id)
11
11
  start_server do
12
- thread = redis_thread 4, "status_updates", "job_messages_#{job_id}"
13
- expect(ConfirmationJob.perform_async 'arg1' => 'val1').to eq(job_id)
12
+ thread = branched_redis_thread 4, "status_updates", "job_messages_#{job_id}" do
13
+ expect(ConfirmationJob.perform_async 'arg1' => 'val1').to eq(job_id)
14
+ end
14
15
  expect(thread.value).to eq([
15
16
  job_id,
16
17
  job_id,
data/spec/spec_helper.rb CHANGED
@@ -60,8 +60,47 @@ def redis_thread messages_limit, *channels
60
60
 
61
61
  end
62
62
 
63
+ def redis_client_thread message_limit, *channels
64
+ thread = Thread.new {
65
+ messages = []
66
+ Sidekiq.redis do |conn|
67
+ puts "Subscribing to #{channels} for #{message_limit.to_s.bold} messages".cyan if ENV['DEBUG']
68
+ pubsub = conn.pubsub
69
+ pubsub.call("SUBSCRIBE", *channels)
70
+
71
+ timeouts = 0
72
+ loop do
73
+ type, ch, msg = pubsub.next_event(2)
74
+ next if type == "subscribe"
75
+ if msg
76
+ puts "Message received: #{ch} -> #{msg}".white if ENV['DEBUG']
77
+ messages << msg
78
+ break if messages.length >= message_limit
79
+ else
80
+ # no new message was received in the allocated timeout
81
+ timeouts += 1
82
+ break if timeouts >= 30
83
+ end
84
+ end
85
+ end
86
+ puts "Returing from thread".cyan if ENV['DEBUG']
87
+ messages
88
+ }
89
+ sleep 0.1
90
+ yield if block_given?
91
+ thread.join
92
+ end
93
+
94
+ def branched_redis_thread n, *channels, &block
95
+ if Sidekiq.major_version < 7
96
+ redis_thread(n, *channels, &block)
97
+ else
98
+ redis_client_thread(n, *channels, &block)
99
+ end
100
+ end
101
+
63
102
  def capture_status_updates n, &block
64
- redis_thread(n, "status_updates", &block).value
103
+ branched_redis_thread(n, "status_updates", &block).value
65
104
  end
66
105
 
67
106
  # Configures server middleware and launches a sidekiq server
@@ -76,20 +115,19 @@ def start_server server_middleware_options = {}
76
115
 
77
116
  # Load and configure server options
78
117
  require 'sidekiq/cli'
79
- Sidekiq.options[:queues] << 'default'
80
- Sidekiq.options[:require] = File.expand_path 'environment.rb', File.dirname(__FILE__)
81
- Sidekiq.options[:timeout] = 1
82
- Sidekiq.options[:concurrency] = 5
83
118
 
84
119
  # Add the server middleware
85
120
  Sidekiq.configure_server do |config|
86
- config.redis = Sidekiq::RedisConnection.create
121
+ config.concurrency = 5
122
+ config.redis = Sidekiq::RedisConnection.create if Sidekiq.major_version < 7
87
123
  Sidekiq::Status.configure_server_middleware config, server_middleware_options
88
124
  end
89
125
 
90
126
  # Launch
91
127
  puts "Server starting".yellow if ENV['DEBUG']
92
- Sidekiq::CLI.instance.run
128
+ instance = Sidekiq::CLI.instance
129
+ instance.parse(['-r', File.expand_path('environment.rb', File.dirname(__FILE__))])
130
+ instance.run
93
131
 
94
132
  end
95
133
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Tsvigun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-02-03 00:00:00.000000000 Z
12
+ date: 2023-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -17,14 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '5.0'
20
+ version: '6.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '8'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
27
- version: '5.0'
30
+ version: '6.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '8'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: chronic_duration
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -131,21 +137,23 @@ executables: []
131
137
  extensions: []
132
138
  extra_rdoc_files: []
133
139
  files:
140
+ - ".github/workflows/ci.yaml"
134
141
  - ".gitignore"
135
142
  - ".gitlab-ci.yml"
136
143
  - ".rspec"
137
- - ".travis.yml"
138
144
  - Appraisals
139
145
  - CHANGELOG.md
140
146
  - Gemfile
141
147
  - LICENSE
142
148
  - README.md
143
149
  - Rakefile
144
- - gemfiles/sidekiq_5.x.gemfile
145
150
  - gemfiles/sidekiq_6.1.gemfile
146
151
  - gemfiles/sidekiq_6.x.gemfile
152
+ - gemfiles/sidekiq_7.x.gemfile
147
153
  - lib/sidekiq-status.rb
148
154
  - lib/sidekiq-status/client_middleware.rb
155
+ - lib/sidekiq-status/redis_adapter.rb
156
+ - lib/sidekiq-status/redis_client_adapter.rb
149
157
  - lib/sidekiq-status/server_middleware.rb
150
158
  - lib/sidekiq-status/sidekiq_extensions.rb
151
159
  - lib/sidekiq-status/storage.rb
@@ -187,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
195
  - !ruby/object:Gem::Version
188
196
  version: '0'
189
197
  requirements: []
190
- rubygems_version: 3.2.32
198
+ rubygems_version: 3.4.1
191
199
  signing_key:
192
200
  specification_version: 4
193
201
  summary: An extension to the sidekiq message processing to track your jobs
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.6
4
- - 2.7
5
- - 3.0
6
- - ruby-head
7
- gemfile:
8
- - gemfiles/sidekiq_5.x.gemfile
9
- - gemfiles/sidekiq_6.1.gemfile
10
- - gemfiles/sidekiq_6.x.gemfile
11
- before_install:
12
- - gem update --system
13
- - gem update bundler
14
- services: redis
15
- notifications:
16
- email: false
17
- matrix:
18
- fast_finish: true
19
- allow_failures:
20
- - rvm: ruby-head