sidekiq-history 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fed6cd482f9bdb31f5290113d1e691a6b14fac9b
4
+ data.tar.gz: d008a0f65783203548f20a66dba91dffa62c2b03
5
+ SHA512:
6
+ metadata.gz: c453039f4f8716826b19b001642d04b33372285bfb3aff6e5499284edf919aaeae6cc965b26f8bebcb63b69bd82091b7edb639eaf4539c653ef78ee1cd23475b
7
+ data.tar.gz: 36cbbcc84b8858ecded10b0faee6ca2b96337275cfa76c96b84f3dbe82fd25a57fdcbfa27c292d318a10ad1a5808b1ebd6b3d1b3ee17d56e4c5186461f7ad0dc
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sidekiq-history.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Russ Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Sidekiq::History
2
+
3
+ A really simple addition to sidekiq web to enable a job history log.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sidekiq-history'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sidekiq-history
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ module Sidekiq
2
+ module History
3
+ class Middleware
4
+ include Sidekiq::Util
5
+
6
+ attr_accessor :msg
7
+
8
+ def call(worker, msg, queue)
9
+ self.msg = msg
10
+
11
+ data = {
12
+ started_at: Time.now.utc,
13
+ payload: msg,
14
+ worker: msg['class'],
15
+ processor: "#{hostname}:#{process_id}-#{Thread.current.object_id}",
16
+ queue: queue
17
+ }
18
+
19
+ Sidekiq.redis do |conn|
20
+ conn.lpush(LIST_KEY, Sidekiq.dump_json(data))
21
+ unless Sidekiq.history_max_count == false
22
+ conn.ltrim(LIST_KEY, 0, Sidekiq.history_max_count - 1)
23
+ end
24
+ end
25
+
26
+ yield
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Sidekiq
2
+ module History
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ <header class="row">
2
+ <div class="span5">
3
+ <h3>History</h3>
4
+ </div>
5
+ <div class="span4">
6
+ <% if @messages.size > 0 %>
7
+ <%= erb :_paging, :locals => { :url => "#{root_path}history#@name" } %>
8
+ <% end %>
9
+ </div>
10
+ </header>
11
+
12
+ <% if @messages.size > 0 %>
13
+ <table class="table table-striped table-bordered table-white" style="width: 100%; margin: 0; table-layout:fixed;">
14
+ <thead>
15
+ <th style="width: 25%">Worker, Args</th>
16
+ <th style="width: 10%">Queue</th>
17
+ <th style="width: 15%">Started At</th>
18
+ <th style="width: 50%">Processor</th>
19
+ </thead>
20
+ <% @messages.each do |msg| %>
21
+ <tr>
22
+ <td style="overflow: hidden; text-overflow: ellipsis;">
23
+ <%= msg['worker'] %>
24
+ <br />
25
+ <%= msg['payload']['args'].inspect[0..100] %>
26
+ </td>
27
+ <td><%= msg['queue'] %></td>
28
+ <td>
29
+ <%= relative_time(Time.parse(msg['started_at'])) %>
30
+ </td>
31
+ <td style="overflow: auto; padding: 10px;">
32
+ Processor: <%= msg['processor'] %>
33
+ </td>
34
+ </tr>
35
+ <% end %>
36
+ </table>
37
+ <div class="row">
38
+ <div class="span5">
39
+ <form class="form-inline" action="<%= "#{root_path}history/remove" %>" method="post" style="margin: 20px 0">
40
+ <input class="btn btn-danger btn-small" type="submit" name="delete" value="Clear All" />
41
+ <label class="checkbox">
42
+ <input type="checkbox" name="counter" value="true" />
43
+ reset history counter
44
+ </label>
45
+ </form>
46
+ </div>
47
+ </div>
48
+ <% else %>
49
+ <div class="alert alert-success">No jobs found.</div>
50
+ <% end %>
@@ -0,0 +1,22 @@
1
+ module Sidekiq
2
+ module History
3
+ module WebExtension
4
+ def self.registered(app)
5
+ app.get '/history' do
6
+ view_path = File.join(File.expand_path('..', __FILE__), 'views')
7
+
8
+ @count = (params[:count] || 25).to_i
9
+ (@current_page, @total_size, @messages) = page('history', params[:page], @count)
10
+ @messages = @messages.map { |msg| Sidekiq.load_json(msg) }
11
+
12
+ render(:erb, File.read(File.join(view_path, 'history.erb')))
13
+ end
14
+
15
+ app.post "/history/remove" do
16
+ Sidekiq::History.reset_history(counter: params['counter'])
17
+ redirect("#{root_path}history")
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,47 @@
1
+ require 'sidekiq/web'
2
+ require 'sidekiq/history/version'
3
+ require 'sidekiq/history/middleware'
4
+ require 'sidekiq/history/web_extension'
5
+
6
+ module Sidekiq
7
+ def self.history_max_count=(value)
8
+ @history_max_count = value
9
+ end
10
+
11
+ def self.history_max_count
12
+ return 1000 if @history_max_count.nil?
13
+ @history_max_count
14
+ end
15
+
16
+ module History
17
+ LIST_KEY = :history
18
+
19
+ def self.reset_history(options = {})
20
+ Sidekiq.redis { |c|
21
+ c.multi do
22
+ c.del(LIST_KEY)
23
+ c.set('stat:history', 0) if options[:counter] || options['counter']
24
+ end
25
+ }
26
+ end
27
+
28
+ def self.count
29
+ Sidekiq.redis { |r| r.llen(LIST_KEY) }
30
+ end
31
+ end
32
+ end
33
+
34
+ Sidekiq.configure_server do |config|
35
+ config.server_middleware do |chain|
36
+ chain.add Sidekiq::History::Middleware
37
+ end
38
+ end
39
+
40
+ Sidekiq::Web.register(Sidekiq::History::WebExtension)
41
+
42
+ if Sidekiq::Web.tabs.is_a?(Array)
43
+ # For sidekiq < 2.5
44
+ Sidekiq::Web.tabs << 'history'
45
+ else
46
+ Sidekiq::Web.tabs['History'] = 'history'
47
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sidekiq/history/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidekiq-history"
8
+ spec.version = Sidekiq::History::VERSION
9
+ spec.authors = ["Russ Smith"]
10
+ spec.email = ["russ@bashme.org"]
11
+ spec.description = %q{History for sidekiq jobs.}
12
+ spec.summary = %q{History for sidekiq jobs.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "sidekiq", ">= 2.14.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rack-test"
26
+ spec.add_development_dependency "sprockets"
27
+ spec.add_development_dependency "sinatra"
28
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-history
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Russ Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.14.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.14.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sprockets
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sinatra
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: History for sidekiq jobs.
98
+ email:
99
+ - russ@bashme.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/sidekiq/history.rb
110
+ - lib/sidekiq/history/middleware.rb
111
+ - lib/sidekiq/history/version.rb
112
+ - lib/sidekiq/history/views/history.erb
113
+ - lib/sidekiq/history/web_extension.rb
114
+ - sidekiq-history.gemspec
115
+ homepage: ''
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.0.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: History for sidekiq jobs.
139
+ test_files: []
140
+ has_rdoc: