attentive_sidekiq 0.0.1
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 +7 -0
- data/README.md +45 -0
- data/attentive_sidekiq.gemspec +13 -0
- data/lib/attentive_sidekiq.rb +5 -0
- data/lib/attentive_sidekiq/middleware.rb +5 -0
- data/lib/attentive_sidekiq/middleware/client/attentionist.rb +25 -0
- data/lib/attentive_sidekiq/middleware/server/attentionist.rb +23 -0
- data/lib/attentive_sidekiq/web.rb +24 -0
- data/lib/attentive_sidekiq/web/locales/en.yml +7 -0
- data/lib/attentive_sidekiq/web/locales/ru.yml +7 -0
- data/lib/attentive_sidekiq/web/views/disappeared-list.erb +27 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a34e8ef3a9cdeb0c306c2961b32918a49868b459
|
4
|
+
data.tar.gz: 767c629c1d10745291a394f5307c081517c94306
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31f7ac4e961ac93548d441516198cf00a4977a80595370d514293c2cdd92544716973f1b8d8d8cf0607ef4bd71408bc77de936997e6457ef3e86720073275c20
|
7
|
+
data.tar.gz: 9457a05bc349c0a2cbb1351453464a6f2280f548d42b0da8c7add1c0d11e5e966aa13396f69b0c2e90d5fbf52bb3b874ccf8e0bafe9575ce594e85ddc3e0015b
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Attentive Sidekiq
|
2
|
+
|
3
|
+
### Motivation
|
4
|
+
It's common to face the issues with sidekiq killing jobs in the middle of processing and not putting them back to redis.
|
5
|
+
This issue leads to jobs losage, which essentualy means probable loss of critical user data.
|
6
|
+
Sidekiq's author, Mike Perham, suggests purchasing Sidekiq Pro which uses another fetch mechanism providing you with a confidence that ensures jobs persist in redis at any time.
|
7
|
+
However, it is reported by some users to still to cause the same issue.
|
8
|
+
|
9
|
+
|
10
|
+
### About
|
11
|
+
Attentive Sidekiq is a sidekiq plugin which monitors the jobs being started but not finished (successfully or badly).
|
12
|
+
It saves started jobs info into redis hash and checks whether any job stays there for too long (without being processed or deleted due to job success/failure).
|
13
|
+
|
14
|
+
### Installation
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'attentive_sidekiq'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
### Usage
|
24
|
+
Configure your middleware chains, lookup Middleware usage on Sidekiq wiki for more info.
|
25
|
+
|
26
|
+
Sidekiq.configure_server do |config|
|
27
|
+
config.server_middleware do |chain|
|
28
|
+
chain.add AttentiveSidekiq::Middleware::Server::Attentionist
|
29
|
+
end
|
30
|
+
config.client_middleware do |chain|
|
31
|
+
chain.add AttentiveSidekiq::Middleware::Client::Attentionist
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Sidekiq.configure_client do |config|
|
36
|
+
config.client_middleware do |chain|
|
37
|
+
chain.add AttentiveSidekiq::Middleware::Client::Attentionist
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
After that you can use your jobs as usual.
|
42
|
+
|
43
|
+
### Sidekiq Web integration
|
44
|
+
Attentive Sidekiq provides an extension to the Sidekiq web interface that adds a Disappeared Jobs page.
|
45
|
+
To use it, head to your sidekiq dashboard and click the link at the tabs section.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'attentive_sidekiq'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2016-10-31'
|
5
|
+
s.summary = "Make your sidekiq to be attentive to lost jobs"
|
6
|
+
s.description = "This gem allows you to watch the jobs which suddenly dissappeared from redis without being completed by redis worker"
|
7
|
+
s.authors = ["twonegatives"]
|
8
|
+
s.email = 'whitewhiteheaven@gmail.com'
|
9
|
+
s.files = Dir['**/*'].keep_if{ |file| File.file?(file) }
|
10
|
+
s.homepage =
|
11
|
+
'http://rubygems.org/gems/attentive_sidekiq'
|
12
|
+
s.license = 'MIT'
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module AttentiveSidekiq
|
2
|
+
module Middleware
|
3
|
+
module Client
|
4
|
+
class Attentionist
|
5
|
+
|
6
|
+
def call(worker_class, item, queue, redis_pool = nil)
|
7
|
+
yield
|
8
|
+
end
|
9
|
+
|
10
|
+
#def call(worker_class, item, queue, redis_pool = nil)
|
11
|
+
# yield
|
12
|
+
# if rerun?(item["jid"])
|
13
|
+
# mark_as_not_lost(item["jid"])
|
14
|
+
# else
|
15
|
+
# add_to_observed_list(item)
|
16
|
+
# end
|
17
|
+
#end
|
18
|
+
|
19
|
+
#def rerun?(jid)
|
20
|
+
# Sidekiq.redis{|conn| conn.hexists(AttentiveSidekiq::Middleware::REDIS_KEY, jid) } == 1
|
21
|
+
#end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AttentiveSidekiq
|
2
|
+
module Middleware
|
3
|
+
module Server
|
4
|
+
class Attentionist
|
5
|
+
|
6
|
+
def call(worker_instance, item, queue)
|
7
|
+
add_to_observed_list(item)
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
mark_as_not_lost(item["jid"])
|
11
|
+
end
|
12
|
+
|
13
|
+
def mark_as_not_lost(jid)
|
14
|
+
Sidekiq.redis{|conn| conn.hdel(AttentiveSidekiq::Middleware::REDIS_KEY, jid)}
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_to_observed_list(item)
|
18
|
+
Sidekiq.redis{ |conn| conn.hset(AttentiveSidekiq::Middleware::REDIS_KEY, item['jid'], item.to_json) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AttentiveSidekiq
|
2
|
+
module Web
|
3
|
+
VIEW_PATH = File.expand_path("../web/views", __FILE__)
|
4
|
+
|
5
|
+
def self.registered(app)
|
6
|
+
app.helpers do
|
7
|
+
def jobs_not_finished
|
8
|
+
jsoned_jobs = Sidekiq.redis{|conn| conn.hvals(AttentiveSidekiq::Middleware::REDIS_KEY)}
|
9
|
+
jsoned_jobs.map!{|i| JSON.parse(i)}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
app.get('/disappeared-jobs') do
|
14
|
+
jobs_active_now = Set.new(Sidekiq::Workers.new.to_a.map{|i| i[2]["payload"]["jid"]})
|
15
|
+
@suspicious_jobs = jobs_not_finished.delete_if{|i| jobs_active_now.include?(i["jid"])}
|
16
|
+
erb File.read(File.join(VIEW_PATH, 'disappeared-list.erb'))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Sidekiq::Web.register AttentiveSidekiq::Web
|
23
|
+
Sidekiq::Web.locales << File.expand_path(File.dirname(__FILE__) + "/web/locales")
|
24
|
+
Sidekiq::Web.tabs['disappeared_jobs'] = 'disappeared-jobs'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<h3><%= t('disappeared_jobs') %></h3>
|
2
|
+
|
3
|
+
<div class="table_container">
|
4
|
+
<table class="table table-hover table-bordered table-striped table-white">
|
5
|
+
<thead>
|
6
|
+
<tr>
|
7
|
+
<th><%= t('jid') %></th>
|
8
|
+
<th><%= t('queue') %></th>
|
9
|
+
<th><%= t('class') %></th>
|
10
|
+
<th><%= t('arguments') %></th>
|
11
|
+
<th><%= t('time') %></th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
|
15
|
+
<tbody>
|
16
|
+
<% @suspicious_jobs.each do |job| %>
|
17
|
+
<tr>
|
18
|
+
<td><%= job['jid'] %></td>
|
19
|
+
<td><%= job['queue'] %></td>
|
20
|
+
<td><%= job['class'] %></td>
|
21
|
+
<td><%= job['args'] %></td>
|
22
|
+
<td><%= Time.at(job['created_at']).strftime("%H:%M:%S %d.%m.%Y %z") %></td>
|
23
|
+
</tr>
|
24
|
+
<% end %>
|
25
|
+
</tbody>
|
26
|
+
</table>
|
27
|
+
</div>
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attentive_sidekiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- twonegatives
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem allows you to watch the jobs which suddenly dissappeared from
|
14
|
+
redis without being completed by redis worker
|
15
|
+
email: whitewhiteheaven@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- attentive_sidekiq.gemspec
|
22
|
+
- lib/attentive_sidekiq.rb
|
23
|
+
- lib/attentive_sidekiq/middleware.rb
|
24
|
+
- lib/attentive_sidekiq/middleware/client/attentionist.rb
|
25
|
+
- lib/attentive_sidekiq/middleware/server/attentionist.rb
|
26
|
+
- lib/attentive_sidekiq/web.rb
|
27
|
+
- lib/attentive_sidekiq/web/locales/en.yml
|
28
|
+
- lib/attentive_sidekiq/web/locales/ru.yml
|
29
|
+
- lib/attentive_sidekiq/web/views/disappeared-list.erb
|
30
|
+
homepage: http://rubygems.org/gems/attentive_sidekiq
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.5.1
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Make your sidekiq to be attentive to lost jobs
|
54
|
+
test_files: []
|