sidekiq-status 0.6.0 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yaml +53 -0
  3. data/.gitignore +4 -1
  4. data/.gitlab-ci.yml +17 -0
  5. data/Appraisals +11 -0
  6. data/CHANGELOG.md +36 -18
  7. data/Gemfile +0 -4
  8. data/README.md +129 -50
  9. data/Rakefile +2 -0
  10. data/gemfiles/sidekiq_6.1.gemfile +7 -0
  11. data/gemfiles/sidekiq_6.x.gemfile +7 -0
  12. data/gemfiles/sidekiq_7.x.gemfile +7 -0
  13. data/lib/sidekiq-status/client_middleware.rb +46 -8
  14. data/lib/sidekiq-status/redis_adapter.rb +18 -0
  15. data/lib/sidekiq-status/redis_client_adapter.rb +14 -0
  16. data/lib/sidekiq-status/server_middleware.rb +76 -20
  17. data/lib/sidekiq-status/sidekiq_extensions.rb +7 -0
  18. data/lib/sidekiq-status/storage.rb +19 -9
  19. data/lib/sidekiq-status/testing/inline.rb +10 -0
  20. data/lib/sidekiq-status/version.rb +1 -1
  21. data/lib/sidekiq-status/web.rb +116 -25
  22. data/lib/sidekiq-status/worker.rb +12 -5
  23. data/lib/sidekiq-status.rb +40 -5
  24. data/sidekiq-status.gemspec +7 -4
  25. data/spec/environment.rb +1 -0
  26. data/spec/lib/sidekiq-status/client_middleware_spec.rb +15 -12
  27. data/spec/lib/sidekiq-status/server_middleware_spec.rb +66 -22
  28. data/spec/lib/sidekiq-status/web_spec.rb +62 -15
  29. data/spec/lib/sidekiq-status/worker_spec.rb +19 -1
  30. data/spec/lib/sidekiq-status_spec.rb +94 -21
  31. data/spec/spec_helper.rb +104 -26
  32. data/spec/support/test_jobs.rb +71 -6
  33. data/web/sidekiq-status-single-web.png +0 -0
  34. data/web/views/status.erb +118 -0
  35. data/web/views/status_not_found.erb +6 -0
  36. data/web/views/statuses.erb +108 -22
  37. metadata +74 -13
  38. data/.travis.yml +0 -16
  39. data/gemfiles/Gemfile.sidekiq-2 +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8c3bd23f9fe0e80f8354ca3860fbeb5e5f7ca44d
4
- data.tar.gz: 1ad626cad36a7f56fab5f4ca89350c55879a2d86
2
+ SHA256:
3
+ metadata.gz: 7c4653623b20223d993b2c5f2ce82a1ee214083c1adb51530a76d82e4d2b3977
4
+ data.tar.gz: 6cee1ff677b1b964465e79facf5dd1e747c6747f9e99c7fd54e0330082a4b201
5
5
  SHA512:
6
- metadata.gz: 46cbab187b63bc2fb458e7530180a7f0b41858067213346297ec45dc62bdd04db997b2e2031205cf426d3e6eafe9921c4d22491cbcb7f86be0dda4875e3ac8d6
7
- data.tar.gz: e187d76f19d38d903df4258d8a55627da09e5cf4a9faf20b51ce16f682206cbe526142a4c88b8abb3fa993ab2bca7e21866dcd9e5e4591fe937fb3ce7c1810cb
6
+ metadata.gz: 99971994088169aa3ba0c21417557ce9d9fc072917b06c05a9cb7815f0405e331882f057d56079b41256f028c8248a780d9f74592a660a850959109a579519cc
7
+ data.tar.gz: aa7030ebbbb8161f5e9e81c3fac25357cac7bff62d810a3f785e9343c12c3a5839f94060d993aafc5381700b7803ca5e1de17dcb00762525eda6fa9a6bdb4725
@@ -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/.gitignore CHANGED
@@ -1,7 +1,10 @@
1
+ gemfiles/*.lock
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
4
5
  .config
6
+ .rvmrc
7
+ .ruby-version
5
8
  .yardoc
6
9
  Gemfile.lock
7
10
  InstalledFiles
@@ -16,4 +19,4 @@ test/tmp
16
19
  test/version_tmp
17
20
  tmp
18
21
 
19
- .idea/
22
+ .idea/
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,17 @@
1
+ dependency_scanning:
2
+ image: docker:stable
3
+ variables:
4
+ DOCKER_DRIVER: overlay2
5
+ allow_failure: true
6
+ services:
7
+ - docker:stable-dind
8
+ script:
9
+ - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
10
+ - docker run
11
+ --env DEP_SCAN_DISABLE_REMOTE_CHECKS="${DEP_SCAN_DISABLE_REMOTE_CHECKS:-false}"
12
+ --volume "$PWD:/code"
13
+ --volume /var/run/docker.sock:/var/run/docker.sock
14
+ "registry.gitlab.com/gitlab-org/security-products/dependency-scanning:$SP_VERSION" /code
15
+ artifacts:
16
+ reports:
17
+ dependency_scanning: gl-dependency-scanning-report.json
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise "sidekiq-5.x" do
2
+ gem "sidekiq", "~> 5"
3
+ end
4
+
5
+ appraise "sidekiq-6.1" do
6
+ gem "sidekiq", "~> 6.1"
7
+ end
8
+
9
+ appraise "sidekiq-6.x" do
10
+ gem "sidekiq", "~> 6"
11
+ end
data/CHANGELOG.md CHANGED
@@ -1,23 +1,41 @@
1
- Version 0.6.0
2
- + Updated Web UI
3
- + Will have all job statuses, previously it was showing only :working status
4
- + Bootstrap lables instead of badges for status
5
- + Added Arguments column to statuses page
6
- + New :interrupted status added
7
- + Added way to specify :expiration for Sidekiq::Status::ClientMiddleware
8
- + Bug fixes & Code cleaup
1
+ **Version 3.0.3**
2
+ - Fixes a Sidekiq warning about the deprecated `hmset` redis command (https://github.com/kenaniah/sidekiq-status/pull/37)
9
3
 
10
- Version 0.5.3
11
- + some tweaks in web UI, separate redis namespace
4
+ **Version 3.0.2**
5
+ - Avoids setting statuses for non-status jobs when an exception is thrown (https://github.com/kenaniah/sidekiq-status/pull/32)
12
6
 
13
- Version 0.5.2
14
- + Sidekiq versions up to 3.3.* supported, jobs sorting options in web UI, more ruby versions
7
+ **Version 3.0.1**
8
+ - Adds elapsed time and ETA to the job status page (https://github.com/kenaniah/sidekiq-status/pull/13)
15
9
 
16
- Version 0.5.1
17
- + dependencies versions requirements relaxed
10
+ **Version 3.0.0**
11
+ - Drops support for Sidekiq 5.x
12
+ - Adds support for Sidekiq 7.x
13
+ - Migrates from Travis CI to GitHub Actions
18
14
 
19
- Version 0.5.0
20
- + Sidekiq v3 support, redis pools support
15
+ **Version 2.1.3**
16
+ - Fixes redis deprecation warnings (https://github.com/kenaniah/sidekiq-status/issues/11)
21
17
 
22
- Version 0.4.0
23
- + WebUI added, per-worker expiration setting enabled
18
+ **Version 2.1.2**
19
+ - Casts values to strings when HTML-encoding
20
+
21
+ **Version 2.1.1**
22
+ - Ensures parameter outputs are properly HTML-encoded
23
+
24
+ **Version 2.1.0**
25
+ - Adds support for Sidekiq 6.2.2+ (https://github.com/mperham/sidekiq/issues/4955)
26
+
27
+ **Version 2.0.2**
28
+ - Fixes for dark mode theme
29
+
30
+ **Version 2.0.1**
31
+ - Adds support for dark mode to the job status page
32
+
33
+ **Version 2.0.0**
34
+ - Adds support for Ruby 2.7, 3.0
35
+ - Adds support for Sidekiq 6.x
36
+ - Removes support for Ruby 2.3, 2.4, 2.5
37
+ - Removes support for Sidekiq 3.x, 4.x
38
+
39
+ **Versions 1.1.4 and prior**
40
+
41
+ See https://github.com/utgarda/sidekiq-status/blob/master/CHANGELOG.md.
data/Gemfile CHANGED
@@ -2,7 +2,3 @@
2
2
  source "https://rubygems.org"
3
3
 
4
4
  gemspec
5
-
6
- group :test do
7
- gem 'celluloid'
8
- end
data/README.md CHANGED
@@ -1,52 +1,72 @@
1
1
  # Sidekiq::Status
2
- [![Gem Version](https://badge.fury.io/rb/sidekiq-status.png)](http://badge.fury.io/rb/sidekiq-status)
3
- [![Code Climate](https://codeclimate.com/github/utgarda/sidekiq-status.png)](https://codeclimate.com/github/utgarda/sidekiq-status)
4
- [![Build Status](https://secure.travis-ci.org/utgarda/sidekiq-status.png)](http://travis-ci.org/utgarda/sidekiq-status)
5
- [![Dependency Status](https://gemnasium.com/utgarda/sidekiq-status.svg)](https://gemnasium.com/utgarda/sidekiq-status)
6
- [![Inline docs](http://inch-ci.org/github/utgarda/sidekiq-status.svg?branch=master)](http://inch-ci.org/github/utgarda/sidekiq-status)
2
+ [![Gem Version](https://badge.fury.io/rb/sidekiq-status.svg)](https://badge.fury.io/rb/sidekiq-status)
3
+ [![Build Status](https://github.com/kenaniah/sidekiq-status/actions/workflows/ci.yaml/badge.svg)](https://github.com/kenaniah/sidekiq-status/actions/)
7
4
 
8
- An extension to [Sidekiq](http://github.com/mperham/sidekiq) message processing to track your jobs. Inspired
9
- by [resque-status](http://github.com/quirkey/resque-status) and mostly copying its features, using Sidekiq's middleware.
5
+ 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).
6
+
7
+ Requires Ruby 2.6+ and Sidekiq 6.0+ or newer.
10
8
 
11
9
  ## Installation
12
10
 
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'sidekiq-status'
15
+ ```
16
+
17
+ Or install it yourself as:
18
+
19
+ ```bash
13
20
  gem install sidekiq-status
21
+ ```
22
+
23
+ ### Migrating to Version 3.x from 2.x
24
+
25
+ Version 3.0.0 adds support for Sidekiq 7.x, but drops support for Sidekiq 5.x. **You should be able to upgrade cleanly from version 2.x to 3.x provided you are running Sidekiq 6.x or newer.**
26
+
27
+ #### Migrating to Version 2.x from 1.x
28
+
29
+ Version 2.0.0 was published in order to add support for Ruby 3.0 and Sidekiq 6.x and to remove support for versions of both that are now end-of-life. **You should be able to upgrade cleanly from version 1.x to 2.x provided you are running Sidekiq 5.x or newer.**
30
+
31
+ Sidekiq-status version 1.1.4 provides support all the way back to Sidekiq 3.x and was maintained at https://github.com/utgarda/sidekiq-status/.
32
+
33
+ ## Setup Checklist
14
34
 
15
- ## Usage
35
+ To get started:
36
+
37
+ * [Configure](#configuration) the middleware
38
+ * (Optionally) add the [web interface](#adding-the-web-interface)
39
+ * (Optionally) enable support for [ActiveJob](#activejob-support)
16
40
 
17
41
  ### Configuration
18
42
 
19
- Configure your middleware chains, lookup [Middleware usage](https://github.com/mperham/sidekiq/wiki/Middleware)
20
- on Sidekiq wiki for more info.
43
+ To use, add sidekiq-status to the middleware chains. See [Middleware usage](https://github.com/mperham/sidekiq/wiki/Middleware)
44
+ on the Sidekiq wiki for more info.
21
45
 
22
46
  ``` ruby
23
47
  require 'sidekiq'
24
48
  require 'sidekiq-status'
25
49
 
26
50
  Sidekiq.configure_client do |config|
27
- config.client_middleware do |chain|
28
- # accepts :expiration (optional)
29
- chain.add Sidekiq::Status::ClientMiddleware, expiration: 30.minutes # default
30
- end
51
+ # accepts :expiration (optional)
52
+ Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes.to_i
31
53
  end
32
54
 
33
55
  Sidekiq.configure_server do |config|
34
- config.server_middleware do |chain|
35
- # accepts :expiration (optional)
36
- chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes # default
37
- end
38
- config.client_middleware do |chain|
39
- # accepts :expiration (optional)
40
- chain.add Sidekiq::Status::ClientMiddleware, expiration: 30.minutes # default
41
- end
56
+ # accepts :expiration (optional)
57
+ Sidekiq::Status.configure_server_middleware config, expiration: 30.minutes.to_i
58
+
59
+ # accepts :expiration (optional)
60
+ Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes.to_i
42
61
  end
43
62
  ```
44
63
 
45
- After that you can use your jobs as usual and only include `Sidekiq::Status::Worker` module if you want additional functionality of tracking progress and passing any data from job to client.
64
+ Include the `Sidekiq::Status::Worker` module in your jobs if you want the additional functionality of tracking progress and storing / retrieving job data.
46
65
 
47
66
  ``` ruby
48
67
  class MyJob
49
68
  include Sidekiq::Worker
69
+ include Sidekiq::Status::Worker # enables job status tracking
50
70
 
51
71
  def perform(*args)
52
72
  # your code goes here
@@ -54,14 +74,17 @@ class MyJob
54
74
  end
55
75
  ```
56
76
 
57
- To overwrite expiration on worker basis and don't use global expiration for all workers write a expiration method like this below:
77
+ Note: _only jobs that include `Sidekiq::Status::Worker`_ will have their statuses tracked.
78
+
79
+ To overwrite expiration on a per-worker basis, write an expiration method like the one below:
58
80
 
59
81
  ``` ruby
60
82
  class MyJob
61
83
  include Sidekiq::Worker
84
+ include Sidekiq::Status::Worker # enables job status tracking
62
85
 
63
86
  def expiration
64
- @expiration ||= 60*60*24*30 # 30 days
87
+ @expiration ||= 60 * 60 * 24 * 30 # 30 days
65
88
  end
66
89
 
67
90
  def perform(*args)
@@ -70,19 +93,23 @@ class MyJob
70
93
  end
71
94
  ```
72
95
 
73
- But keep in mind that such thing will store details of job as long as expiration is set, so it may charm your Redis storage/memory consumption. Because Redis stores all data in RAM.
96
+ The job status and any additional stored details will remain in Redis until the expiration time is reached. It is recommended that you find an expiration time that works best for your workload.
74
97
 
75
- ### What is expiration time ?
76
- As you noticed you can set expiration time for jobs globally by expiration option while adding middleware or writing a expiration method on each worker this expiration time is nothing but
98
+ ### Expiration Times
77
99
 
78
- + [Redis expire time](http://redis.io/commands/expire), also know as TTL(time to live)
79
- + After expiration time all the info like status, update_time etc. about the worker disappears.
80
- + It is advised to set this expiration time greater than time required for completion of the job.
81
- + Default expiration time is 30 minutes.
100
+ As sidekiq-status stores information about jobs in Redis, it is necessary to set an expiration time for the data that gets stored. A default expiration time may be configured at the time the middleware is loaded via the `:expiration` parameter.
82
101
 
83
- ### Retrieving status
102
+ As explained above, the default expiration may also be overridden on a per-job basis by defining it within the job itself via a method called `#expiration`.
84
103
 
85
- Query for job status any time later:
104
+ The expiration time set will be used as the [Redis expire time](https://redis.io/commands/expire), which is also known as the TTL (time to live). Once the expiration time has passed, all information about the job's status and any custom data stored via sidekiq-status will disappear.
105
+
106
+ It is advised that you set the expiration time greater than the amount of time required to complete the job.
107
+
108
+ The default expiration time is 30 minutes.
109
+
110
+ ### Retrieving Status
111
+
112
+ You may query for job status any time up to expiration:
86
113
 
87
114
  ``` ruby
88
115
  job_id = MyJob.perform_async(*args)
@@ -90,14 +117,37 @@ job_id = MyJob.perform_async(*args)
90
117
  status = Sidekiq::Status::status(job_id)
91
118
  Sidekiq::Status::queued? job_id
92
119
  Sidekiq::Status::working? job_id
120
+ Sidekiq::Status::retrying? job_id
93
121
  Sidekiq::Status::complete? job_id
94
122
  Sidekiq::Status::failed? job_id
95
123
  Sidekiq::Status::interrupted? job_id
96
124
 
97
125
  ```
98
- Important: If you try any of the above status method after the expiration time, will result into `nil` or `false`
126
+ Important: If you try any of the above status method after the expiration time, the result will be `nil` or `false`.
127
+
128
+ ### ActiveJob Support
129
+
130
+ This gem also supports ActiveJob jobs. Their status will be tracked automatically.
99
131
 
100
- ### Tracking progress, saving, and retrieving data associated with job
132
+ To also enable job progress tracking and data storage features, simply add the `Sidekiq::Status::Worker` module to your base class, like below:
133
+
134
+ ```ruby
135
+ # app/jobs/application_job.rb
136
+ class ApplicationJob < ActiveJob::Base
137
+ include Sidekiq::Status::Worker
138
+ end
139
+
140
+ # app/jobs/my_job.rb
141
+ class MyJob < ApplicationJob
142
+ def perform(*args)
143
+ # your code goes here
144
+ end
145
+ end
146
+ ```
147
+
148
+ ### Tracking Progress and Storing Data
149
+
150
+ sidekiq-status comes with a feature that allows you to track the progress of a job, as well as store and retrieve any custom data related to a job.
101
151
 
102
152
  ``` ruby
103
153
  class MyJob
@@ -109,13 +159,13 @@ class MyJob
109
159
 
110
160
  # the common idiom to track progress of your task
111
161
  total 100 # by default
112
- at 5, "Almost done"
162
+ at 5, "Almost done" # 5/100 = 5 % completion
113
163
 
114
164
  # a way to associate data with your job
115
165
  store vino: 'veritas'
116
166
 
117
- # a way of retrieving said data
118
- # remember that retrieved data is always is String|nil
167
+ # a way of retrieving stored data
168
+ # remember that retrieved data is always String|nil
119
169
  vino = retrieve :vino
120
170
  end
121
171
  end
@@ -128,7 +178,10 @@ Sidekiq::Status::at job_id #=> 5
128
178
  Sidekiq::Status::total job_id #=> 100
129
179
  Sidekiq::Status::message job_id #=> "Almost done"
130
180
  Sidekiq::Status::pct_complete job_id #=> 5
181
+ Sidekiq::Status::working_at job_id #=> 2718
182
+ Sidekiq::Status::update_time job_id #=> 2819
131
183
  ```
184
+
132
185
  ### Unscheduling
133
186
 
134
187
  ```ruby
@@ -137,27 +190,45 @@ Sidekiq::Status.cancel scheduled_job_id #=> true
137
190
  # doesn't cancel running jobs, this is more like unscheduling, therefore an alias:
138
191
  Sidekiq::Status.unschedule scheduled_job_id #=> true
139
192
 
140
- # returns false if invalid or wrong scheduled_job_id is provided
193
+ # returns false if invalid or wrong scheduled_job_id is provided
141
194
  Sidekiq::Status.unschedule some_other_unschedule_job_id #=> false
142
195
  Sidekiq::Status.unschedule nil #=> false
143
196
  Sidekiq::Status.unschedule '' #=> false
144
197
  # Note: cancel and unschedule are alias methods.
145
198
  ```
146
- Important: If you try any of the status method after the expiration time for scheduled jobs, will result into `nil` or `false`. But job will be in sidekiq's scheduled queue and will execute normally, once job is started on scheduled time you will get status info for job till expiration time defined on `Sidekiq::Status::ServerMiddleware`.
199
+ Important: If you schedule a job and then try any of the status methods after the expiration time, the result will be either `nil` or `false`. The job itself will still be in Sidekiq's scheduled queue and will execute normally. Once the job is started at its scheduled time, sidekiq-status' job metadata will once again be added back to Redis and you will be able to get status info for the job until the expiration time.
147
200
 
148
- ### Sidekiq web integration
201
+ ### Deleting Job Status by Job ID
149
202
 
150
- Sidekiq::Status also provides an extension to Sidekiq web interface with a `/statuses`.
151
- ![Sidekiq Status Web](https://raw.github.com/utgarda/sidekiq-status/master/web/sidekiq-status-web.png)
203
+ Job status and metadata will automatically be removed from Redis once the expiration time is reached. But if you would like to remove job information from Redis prior to the TTL expiration, `Sidekiq::Status#delete` will do just that. Note that this will also remove any metadata that was stored with the job.
152
204
 
153
- Setup Sidekiq web interface according to Sidekiq documentation and add the Sidekiq::Status::Web require:
205
+ ```ruby
206
+ # returns number of keys/jobs that were removed
207
+ Sidekiq::Status.delete(job_id) #=> 1
208
+ Sidekiq::Status.delete(bad_job_id) #=> 0
209
+ ```
210
+
211
+ ### Sidekiq Web Integration
212
+
213
+ This gem provides an extension to Sidekiq's web interface with an index at `/statuses`.
214
+
215
+ ![Sidekiq Status Web](web/sidekiq-status-web.png)
216
+
217
+ Information for an individual job may be found at `/statuses/:job_id`.
218
+
219
+ ![Sidekiq Status Web](web/sidekiq-status-single-web.png)
220
+
221
+ Note: _only jobs that include `Sidekiq::Status::Worker`_ will be reported in the web interface.
222
+
223
+ #### Adding the Web Interface
224
+
225
+ To use, setup the Sidekiq Web interface according to Sidekiq documentation and add the `Sidekiq::Status::Web` require:
154
226
 
155
227
  ``` ruby
156
228
  require 'sidekiq/web'
157
229
  require 'sidekiq-status/web'
158
230
  ```
159
231
 
160
-
161
232
  ### Testing
162
233
 
163
234
  Drawing analogy from [sidekiq testing by inlining](https://github.com/mperham/sidekiq/wiki/Testing#testing-workers-inline),
@@ -177,12 +248,20 @@ To use `sidekiq-status` inlining, require it too in your `{test,spec}_helper.rb`
177
248
 
178
249
  `require 'sidekiq-status/testing/inline'`
179
250
 
251
+ ## Contributing
252
+
253
+ Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
180
254
 
181
- ### Features coming
182
- * Stopping jobs by id
255
+ 1. Fork it
256
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
257
+ 3. Commit your changes along with test cases (`git commit -am 'Add some feature'`)
258
+ 4. If possible squash your commits to one commit if they all belong to same feature.
259
+ 5. Push to the branch (`git push origin my-new-feature`)
260
+ 6. Create new Pull Request.
183
261
 
184
262
  ## Thanks
185
263
  * Pramod Shinde
264
+ * Kenaniah Cerny
186
265
  * Clay Allsopp
187
266
  * Andrew Korzhuev
188
267
  * Jon Moses
@@ -193,5 +272,5 @@ To use `sidekiq-status` inlining, require it too in your `{test,spec}_helper.rb`
193
272
  * Ben Sharpe
194
273
 
195
274
  ## License
196
- MIT License , see LICENSE for more details.
197
- © 2012 - 2015 Evgeniy Tsvigun
275
+ MIT License, see LICENSE for more details.
276
+ © 2012 - 2016 Evgeniy Tsvigun
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+
3
+ require "bundler/setup"
2
4
  require "bundler/gem_tasks"
3
5
 
4
6
  require 'rspec/core/rake_task'
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 6.1"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 6"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 7"
6
+
7
+ gemspec path: "../"
@@ -1,3 +1,6 @@
1
+ require 'sidekiq/api'
2
+ JOB_CLASS = Sidekiq.constants.include?(:JobRecord) ? Sidekiq::JobRecord : Sidekiq::Job
3
+
1
4
  module Sidekiq::Status
2
5
  # Should be in the client middleware chain
3
6
  class ClientMiddleware
@@ -17,14 +20,49 @@ module Sidekiq::Status
17
20
  # @param [String] queue the queue's name
18
21
  # @param [ConnectionPool] redis_pool optional redis connection pool
19
22
  def call(worker_class, msg, queue, redis_pool=nil)
20
- initial_metadata = {
21
- jid: msg['jid'],
22
- status: :queued,
23
- worker: worker_class,
24
- args: msg['args'].to_a.empty? ? nil : msg['args'].to_json
25
- }
26
- store_for_id msg['jid'], initial_metadata, @expiration, redis_pool
23
+
24
+ # Determine the actual job class
25
+ klass = msg["args"][0]["job_class"] || worker_class rescue worker_class
26
+ job_class = if klass.is_a?(Class)
27
+ klass
28
+ elsif Module.const_defined?(klass)
29
+ Module.const_get(klass)
30
+ else
31
+ nil
32
+ end
33
+
34
+ # Store data if the job is a Sidekiq::Status::Worker
35
+ if job_class && job_class.ancestors.include?(Sidekiq::Status::Worker)
36
+ initial_metadata = {
37
+ jid: msg['jid'],
38
+ status: :queued,
39
+ worker: JOB_CLASS.new(msg, queue).display_class,
40
+ args: display_args(msg, queue)
41
+ }
42
+ store_for_id msg['jid'], initial_metadata, job_class.new.expiration || @expiration, redis_pool
43
+ end
44
+
27
45
  yield
46
+
47
+ end
48
+
49
+ def display_args(msg, queue)
50
+ job = JOB_CLASS.new(msg, queue)
51
+ return job.display_args.to_a.empty? ? "{}" : job.display_args.to_json
52
+ rescue Exception => e
53
+ # For Sidekiq ~> 2.7
54
+ return msg['args'].to_a.empty? ? nil : msg['args'].to_json
55
+ end
56
+ end
57
+
58
+ # Helper method to easily configure sidekiq-status client middleware
59
+ # whatever the Sidekiq version is.
60
+ # @param [Sidekiq] sidekiq_config the Sidekiq config
61
+ # @param [Hash] client_middleware_options client middleware initialization options
62
+ # @option client_middleware_options [Fixnum] :expiration ttl for complete jobs
63
+ def self.configure_client_middleware(sidekiq_config, client_middleware_options = {})
64
+ sidekiq_config.client_middleware do |chain|
65
+ chain.add Sidekiq::Status::ClientMiddleware, client_middleware_options
28
66
  end
29
67
  end
30
- end
68
+ end
@@ -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