sidekiq-status 0.7.0 → 0.8.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
  SHA1:
3
- metadata.gz: 1750cf2e429082ad9d404598e45fe7bf15bb31cc
4
- data.tar.gz: 708de7f5f0a83d59fec644600f2a4e70e99c89d5
3
+ metadata.gz: 5c97c75d07e08298c13cd5b502d3d75f812f1de2
4
+ data.tar.gz: ed623bce78155a817cc1b29479ae4d11ca0cbaba
5
5
  SHA512:
6
- metadata.gz: 7228891c5252a1df3da9ad85942552f5426a466d18ddc6b9e963ad3ec6f91512ecaadeb8e0ff00c09f36d2c9a044cfb44619271b772637b88c044868d15fdc4c
7
- data.tar.gz: 56a416d652d875528fd64cebaa490fc3ae173ba96d8ea080c7d2d202a67ecdc11d365c66d3d4cac4691977a5d8d2b006addc0f84cbb2a7fca52ad3fa5cb07530
6
+ metadata.gz: f46cff2d00bc9d824888a1b06a5586418f8072a93b7161fba30896ea4b34ef4fc4145516549fbc556f2fbe40ea0180c4dc906942b9599fcba3227018d0ec43ce
7
+ data.tar.gz: 017db214e0b033de8f93cb6116e4759c67e04d8f95f500f1bd61d62fdd99aeaf2f3250b199caebe05a17de07f667502a4b5259ba499c65d7bababbacae4f20f8
data/.gitignore CHANGED
@@ -1,7 +1,9 @@
1
+ gemfiles/*.lock
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
4
5
  .config
6
+ .rvmrc
5
7
  .yardoc
6
8
  Gemfile.lock
7
9
  InstalledFiles
@@ -16,4 +18,4 @@ test/tmp
16
18
  test/version_tmp
17
19
  tmp
18
20
 
19
- .idea/
21
+ .idea/
data/.travis.yml CHANGED
@@ -3,8 +3,11 @@ rvm:
3
3
  - 2.2
4
4
  - 2.3
5
5
  - 2.4
6
+ - 2.5
6
7
  gemfile:
7
- - Gemfile
8
+ - gemfiles/sidekiq_3.x.gemfile
9
+ - gemfiles/sidekiq_4.x.gemfile
10
+ - gemfiles/sidekiq_5.x.gemfile
8
11
  before_install:
9
12
  - gem update --system
10
13
  - gem update bundler
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise "sidekiq-3.x" do
2
+ gem "sidekiq", "~> 3"
3
+ end
4
+
5
+ appraise "sidekiq-4.x" do
6
+ gem "sidekiq", "~> 4"
7
+ end
8
+
9
+ appraise "sidekiq-5.x" do
10
+ gem "sidekiq", "~> 5"
11
+ end
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- Version 0.7.0
1
+ **Version 0.8.0**
2
+ + Properly ignores jobs that do not have `Sidekiq::Status::Worker` included
3
+ + Honors custom job expirations for ActiveJob jobs
4
+ + Adds a `:retrying` status
5
+ + Adds remove / retry buttons to the index page
6
+ + Server middleware will now catches all exception types
7
+ + Changes where server middleware is inserted in the chain
8
+ + Reduces the amount of Redis calls made
9
+ + Adds pagination / per page setting
10
+ + Restores column sorting functionality
11
+
12
+ **Version 0.7.0**
2
13
  + Sidekiq 4.2 and 5 now supported
3
14
  + Added full support for ActiveJob
4
15
  + Updated Web UI
@@ -8,7 +19,7 @@ Version 0.7.0
8
19
  + Times now display using natural language via ChronicDuration
9
20
  + Test suite fixed
10
21
 
11
- Version 0.6.0
22
+ **Version 0.6.0**
12
23
  + Updated Web UI
13
24
  + Will have all job statuses, previously it was showing only :working status
14
25
  + Bootstrap lables instead of badges for status
@@ -17,17 +28,17 @@ Version 0.6.0
17
28
  + Added way to specify :expiration for Sidekiq::Status::ClientMiddleware
18
29
  + Bug fixes & Code cleaup
19
30
 
20
- Version 0.5.3
31
+ **Version 0.5.3**
21
32
  + some tweaks in web UI, separate redis namespace
22
33
 
23
- Version 0.5.2
34
+ **Version 0.5.2**
24
35
  + Sidekiq versions up to 3.3.* supported, jobs sorting options in web UI, more ruby versions
25
36
 
26
- Version 0.5.1
37
+ **Version 0.5.1**
27
38
  + dependencies versions requirements relaxed
28
39
 
29
- Version 0.5.0
40
+ **Version 0.5.0**
30
41
  + Sidekiq v3 support, redis pools support
31
42
 
32
- Version 0.4.0
43
+ **Version 0.4.0**
33
44
  + WebUI added, per-worker expiration setting enabled
data/README.md CHANGED
@@ -1,13 +1,17 @@
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)
2
+ [![Gem Version](https://badge.fury.io/rb/sidekiq-status.svg)](http://badge.fury.io/rb/sidekiq-status)
3
+ [![Code Climate](https://codeclimate.com/github/utgarda/sidekiq-status.svg)](https://codeclimate.com/github/utgarda/sidekiq-status)
4
+ [![Build Status](https://secure.travis-ci.org/utgarda/sidekiq-status.svg)](http://travis-ci.org/utgarda/sidekiq-status)
5
5
  [![Dependency Status](https://gemnasium.com/utgarda/sidekiq-status.svg)](https://gemnasium.com/utgarda/sidekiq-status)
6
6
  [![Inline docs](http://inch-ci.org/github/utgarda/sidekiq-status.svg?branch=master)](http://inch-ci.org/github/utgarda/sidekiq-status)
7
7
 
8
8
  An extension to [Sidekiq](http://github.com/mperham/sidekiq) message processing to track your jobs. Inspired
9
9
  by [resque-status](http://github.com/quirkey/resque-status) and mostly copying its features, using Sidekiq's middleware.
10
10
 
11
+ Fully compatible with ActiveJob.
12
+
13
+ Supports the latest versions of Sidekiq and all the way back to 3.x.
14
+
11
15
  ## Installation
12
16
 
13
17
  Add this line to your application's Gemfile:
@@ -15,49 +19,58 @@ Add this line to your application's Gemfile:
15
19
  ```ruby
16
20
  gem 'sidekiq-status'
17
21
  ```
22
+
18
23
  And then execute:
19
24
 
20
- $ bundle
25
+ ```bash
26
+ $ bundle
27
+ ```
21
28
 
22
29
  Or install it yourself as:
23
30
 
24
- gem install sidekiq-status
31
+ ```bash
32
+ gem install sidekiq-status
33
+ ```
34
+
35
+ ## Setup Checklist
36
+
37
+ To get started:
25
38
 
26
- ## Usage
39
+ * [Configure](#configuration) the middleware
40
+ * (Optionally) add the [web interface](#adding-the-web-interface)
41
+ * (Optionally) enable support for [ActiveJob](#activejob-support)
27
42
 
28
43
  ### Configuration
29
44
 
30
- Configure your middleware chains, lookup [Middleware usage](https://github.com/mperham/sidekiq/wiki/Middleware)
31
- on Sidekiq wiki for more info.
45
+ To use, add sidekiq-status to the middleware chains. See [Middleware usage](https://github.com/mperham/sidekiq/wiki/Middleware)
46
+ on the Sidekiq wiki for more info.
32
47
 
33
48
  ``` ruby
34
49
  require 'sidekiq'
35
50
  require 'sidekiq-status'
36
51
 
37
52
  Sidekiq.configure_client do |config|
38
- config.client_middleware do |chain|
39
- # accepts :expiration (optional)
40
- chain.add Sidekiq::Status::ClientMiddleware, expiration: 30.minutes # default
41
- end
53
+ # accepts :expiration (optional)
54
+ Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes
42
55
  end
43
56
 
44
57
  Sidekiq.configure_server do |config|
45
- config.server_middleware do |chain|
46
- # accepts :expiration (optional)
47
- chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes # default
48
- end
49
- config.client_middleware do |chain|
50
- # accepts :expiration (optional)
51
- chain.add Sidekiq::Status::ClientMiddleware, expiration: 30.minutes # default
52
- end
58
+ # accepts :expiration (optional)
59
+ Sidekiq::Status.configure_server_middleware config, expiration: 30.minutes
60
+
61
+ # accepts :expiration (optional)
62
+ Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes
53
63
  end
54
64
  ```
55
65
 
56
- 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.
66
+ **Note:** This method of configuration is new as of version 0.8.0.
67
+
68
+ After that you can use your jobs as usual. You need to also include the `Sidekiq::Status::Worker` module in your jobs if you want the additional functionality of tracking progress and storing / retrieving job data.
57
69
 
58
70
  ``` ruby
59
71
  class MyJob
60
72
  include Sidekiq::Worker
73
+ include Sidekiq::Status::Worker # enables job status tracking
61
74
 
62
75
  def perform(*args)
63
76
  # your code goes here
@@ -65,14 +78,17 @@ class MyJob
65
78
  end
66
79
  ```
67
80
 
68
- To overwrite expiration on worker basis and don't use global expiration for all workers write a expiration method like this below:
81
+ As of version 0.8.0, _only jobs that include `Sidekiq::Status::Worker`_ will have their statuses tracked. Previous versions of this gem used to track statuses for all jobs, even when `Sidekiq::Status::Worker` was not included.
82
+
83
+ To overwrite expiration on a per-worker basis, write an expiration method like the one below:
69
84
 
70
85
  ``` ruby
71
86
  class MyJob
72
87
  include Sidekiq::Worker
88
+ include Sidekiq::Status::Worker # enables job status tracking
73
89
 
74
90
  def expiration
75
- @expiration ||= 60*60*24*30 # 30 days
91
+ @expiration ||= 60 * 60 * 24 * 30 # 30 days
76
92
  end
77
93
 
78
94
  def perform(*args)
@@ -81,19 +97,23 @@ class MyJob
81
97
  end
82
98
  ```
83
99
 
84
- 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.
100
+ 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.
101
+
102
+ ### Expiration Times
103
+
104
+ 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.
85
105
 
86
- ### What is expiration time ?
87
- 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
106
+ 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`.
88
107
 
89
- + [Redis expire time](http://redis.io/commands/expire), also know as TTL(time to live)
90
- + After expiration time all the info like status, update_time etc. about the worker disappears.
91
- + It is advised to set this expiration time greater than time required for completion of the job.
92
- + Default expiration time is 30 minutes.
108
+ The expiration time set will be used as the [Redis expire time](http://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.
93
109
 
94
- ### Retrieving status
110
+ It is advised that you set the expiration time greater than the amount of time required to complete the job.
95
111
 
96
- Query for job status any time later:
112
+ The default expiration time is 30 minutes.
113
+
114
+ ### Retrieving Status
115
+
116
+ You may query for job status any time up to expiration:
97
117
 
98
118
  ``` ruby
99
119
  job_id = MyJob.perform_async(*args)
@@ -101,14 +121,37 @@ job_id = MyJob.perform_async(*args)
101
121
  status = Sidekiq::Status::status(job_id)
102
122
  Sidekiq::Status::queued? job_id
103
123
  Sidekiq::Status::working? job_id
124
+ Sidekiq::Status::retrying? job_id
104
125
  Sidekiq::Status::complete? job_id
105
126
  Sidekiq::Status::failed? job_id
106
127
  Sidekiq::Status::interrupted? job_id
107
128
 
108
129
  ```
109
- Important: If you try any of the above status method after the expiration time, will result into `nil` or `false`
130
+ Important: If you try any of the above status method after the expiration time, the result will be `nil` or `false`.
131
+
132
+ ### ActiveJob Support
110
133
 
111
- ### Tracking progress, saving, and retrieving data associated with job
134
+ Version 0.7.0 has added full support for ActiveJob. The status of ActiveJob jobs will be tracked automatically.
135
+
136
+ To also enable job progress tracking and data storage features, simply add the `Sidekiq::Status::Worker` module to your base class, like below:
137
+
138
+ ```ruby
139
+ # app/jobs/application_job.rb
140
+ class ApplicationJob < ActiveJob::Base
141
+ include Sidekiq::Status::Worker
142
+ end
143
+
144
+ # app/jobs/my_job.rb
145
+ class MyJob < ApplicationJob
146
+ def perform(*args)
147
+ # your code goes here
148
+ end
149
+ end
150
+ ```
151
+
152
+ ### Tracking Progress and Storing Data
153
+
154
+ 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.
112
155
 
113
156
  ``` ruby
114
157
  class MyJob
@@ -120,12 +163,12 @@ class MyJob
120
163
 
121
164
  # the common idiom to track progress of your task
122
165
  total 100 # by default
123
- at 5, "Almost done"
166
+ at 5, "Almost done" # 5/100 = 5 % completion
124
167
 
125
168
  # a way to associate data with your job
126
169
  store vino: 'veritas'
127
170
 
128
- # a way of retrieving said data
171
+ # a way of retrieving stored data
129
172
  # remember that retrieved data is always String|nil
130
173
  vino = retrieve :vino
131
174
  end
@@ -140,6 +183,7 @@ Sidekiq::Status::total job_id #=> 100
140
183
  Sidekiq::Status::message job_id #=> "Almost done"
141
184
  Sidekiq::Status::pct_complete job_id #=> 5
142
185
  ```
186
+
143
187
  ### Unscheduling
144
188
 
145
189
  ```ruby
@@ -148,35 +192,45 @@ Sidekiq::Status.cancel scheduled_job_id #=> true
148
192
  # doesn't cancel running jobs, this is more like unscheduling, therefore an alias:
149
193
  Sidekiq::Status.unschedule scheduled_job_id #=> true
150
194
 
151
- # returns false if invalid or wrong scheduled_job_id is provided
195
+ # returns false if invalid or wrong scheduled_job_id is provided
152
196
  Sidekiq::Status.unschedule some_other_unschedule_job_id #=> false
153
197
  Sidekiq::Status.unschedule nil #=> false
154
198
  Sidekiq::Status.unschedule '' #=> false
155
199
  # Note: cancel and unschedule are alias methods.
156
200
  ```
157
- 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`.
201
+ 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.
202
+
203
+ ### Deleting Job Status by Job ID
204
+
205
+ 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.
158
206
 
159
- ### Deleting Status by Job ID
160
207
  ```ruby
161
208
  # returns number of keys/jobs that were removed
162
209
  Sidekiq::Status.delete(job_id) #=> 1
163
210
  Sidekiq::Status.delete(bad_job_id) #=> 0
164
211
  ```
165
212
 
166
- ### Sidekiq web integration
213
+ ### Sidekiq Web Integration
214
+
215
+ This gem provides an extension to Sidekiq's web interface with an index at `/statuses`.
167
216
 
168
- Sidekiq::Status also provides an extension to Sidekiq web interface with an index at `/statuses` and a single job at `/statuses/123`.
169
217
  ![Sidekiq Status Web](web/sidekiq-status-web.png)
218
+
219
+ As of 0.7.0, status information for an individual job may be found at `/statuses/:job_id`.
220
+
170
221
  ![Sidekiq Status Web](web/sidekiq-status-single-web.png)
171
222
 
172
- Setup Sidekiq web interface according to Sidekiq documentation and add the Sidekiq::Status::Web require:
223
+ As of 0.8.0, only jobs that include `Sidekiq::Status::Worker` will be reported in the web interface.
224
+
225
+ #### Adding the Web Interface
226
+
227
+ To use, setup the Sidekiq Web interface according to Sidekiq documentation and add the `Sidekiq::Status::Web` require:
173
228
 
174
229
  ``` ruby
175
230
  require 'sidekiq/web'
176
231
  require 'sidekiq-status/web'
177
232
  ```
178
233
 
179
-
180
234
  ### Testing
181
235
 
182
236
  Drawing analogy from [sidekiq testing by inlining](https://github.com/mperham/sidekiq/wiki/Testing#testing-workers-inline),
@@ -209,6 +263,7 @@ Bug reports and pull requests are welcome. This project is intended to be a safe
209
263
 
210
264
  ## Thanks
211
265
  * Pramod Shinde
266
+ * Kenaniah Cerny
212
267
  * Clay Allsopp
213
268
  * Andrew Korzhuev
214
269
  * Jon Moses
@@ -219,5 +274,5 @@ Bug reports and pull requests are welcome. This project is intended to be a safe
219
274
  * Ben Sharpe
220
275
 
221
276
  ## License
222
- MIT License , see LICENSE for more details.
277
+ MIT License, see LICENSE for more details.
223
278
  © 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", "~> 3"
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", "~> 4"
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", "~> 5"
6
+
7
+ gemspec path: "../"
@@ -1,4 +1,5 @@
1
- require "sidekiq-status/version"
1
+ require 'sidekiq-status/version'
2
+ require 'sidekiq-status/sidekiq_extensions'
2
3
  require 'sidekiq-status/storage'
3
4
  require 'sidekiq-status/worker'
4
5
  require 'sidekiq-status/client_middleware'
@@ -9,7 +10,7 @@ require 'chronic_duration'
9
10
  module Sidekiq::Status
10
11
  extend Storage
11
12
  DEFAULT_EXPIRY = 60 * 30
12
- STATUS = [ :queued, :working, :complete, :stopped, :failed, :interrupted ].freeze
13
+ STATUS = [ :queued, :working, :retrying, :complete, :stopped, :failed, :interrupted ].freeze
13
14
 
14
15
  class << self
15
16
  # Job status by id
@@ -57,7 +58,7 @@ module Sidekiq::Status
57
58
  end
58
59
 
59
60
  def pct_complete(job_id)
60
- ((at(job_id) / total(job_id).to_f) * 100 ).to_i if total(job_id).to_f > 0
61
+ get(job_id, :pct_complete).to_i
61
62
  end
62
63
 
63
64
  def message(job_id)
@@ -18,14 +18,24 @@ module Sidekiq::Status
18
18
  # @param [String] queue the queue's name
19
19
  # @param [ConnectionPool] redis_pool optional redis connection pool
20
20
  def call(worker_class, msg, queue, redis_pool=nil)
21
- initial_metadata = {
22
- jid: msg['jid'],
23
- status: :queued,
24
- worker: Sidekiq::Job.new(msg, queue).display_class,
25
- args: display_args(msg, queue)
26
- }
27
- store_for_id msg['jid'], initial_metadata, @expiration, redis_pool
21
+
22
+ # Determine the actual job class
23
+ klass = msg["args"][0]["job_class"] || worker_class rescue worker_class
24
+ job_class = klass.is_a?(Class) ? klass : Module.const_get(klass)
25
+
26
+ # Store data if the job is a Sidekiq::Status::Worker
27
+ if job_class.ancestors.include?(Sidekiq::Status::Worker)
28
+ initial_metadata = {
29
+ jid: msg['jid'],
30
+ status: :queued,
31
+ worker: Sidekiq::Job.new(msg, queue).display_class,
32
+ args: display_args(msg, queue)
33
+ }
34
+ store_for_id msg['jid'], initial_metadata, job_class.new.expiration || @expiration, redis_pool
35
+ end
36
+
28
37
  yield
38
+
29
39
  end
30
40
 
31
41
  def display_args(msg, queue)
@@ -36,4 +46,15 @@ module Sidekiq::Status
36
46
  return msg['args'].to_a.empty? ? nil : msg['args'].to_json
37
47
  end
38
48
  end
49
+
50
+ # Helper method to easily configure sidekiq-status client middleware
51
+ # whatever the Sidekiq version is.
52
+ # @param [Sidekiq] sidekiq_config the Sidekiq config
53
+ # @param [Hash] client_middleware_options client middleware initialization options
54
+ # @option client_middleware_options [Fixnum] :expiration ttl for complete jobs
55
+ def self.configure_client_middleware(sidekiq_config, client_middleware_options = {})
56
+ sidekiq_config.client_middleware do |chain|
57
+ chain.add Sidekiq::Status::ClientMiddleware, client_middleware_options
58
+ end
59
+ end
39
60
  end