mirror of
https://github.com/endofunky/sidetiq.git
synced 2022-11-09 13:53:30 -05:00
Initial version of the web extension.
This commit is contained in:
parent
2d73e6f77f
commit
46c013f725
7 changed files with 188 additions and 1 deletions
3
Gemfile
3
Gemfile
|
@ -3,11 +3,14 @@ source 'https://rubygems.org'
|
||||||
group :development do
|
group :development do
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
gem 'rake-compiler'
|
gem 'rake-compiler'
|
||||||
|
gem 'sinatra', require: false
|
||||||
|
gem 'slim', require: false
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'simplecov'
|
gem 'simplecov'
|
||||||
gem 'mocha'
|
gem 'mocha'
|
||||||
|
gem 'rack-test'
|
||||||
end
|
end
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
|
11
README.md
11
README.md
|
@ -77,6 +77,17 @@ Sidetiq.configure do |config|
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## WEB EXTENSION
|
||||||
|
|
||||||
|
Sidetiq includes an extension for Sidekiq's web interface. It will not be
|
||||||
|
loaded by default, so it will have to be required manually:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
require 'sidetiq/web'
|
||||||
|
```
|
||||||
|
|
||||||
|
![Screenshot](http://cl.ly/image/1X0q3v153F3Q)
|
||||||
|
|
||||||
## CONSIDERATIONS
|
## CONSIDERATIONS
|
||||||
|
|
||||||
If workers are spread across multiple machines multiple jobs might be enqueued
|
If workers are spread across multiple machines multiple jobs might be enqueued
|
||||||
|
|
23
lib/sidetiq/views/sidetiq.slim
Normal file
23
lib/sidetiq/views/sidetiq.slim
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
header.row
|
||||||
|
.span5
|
||||||
|
h3 Recurring Jobs
|
||||||
|
|
||||||
|
- if @schedules.length > 0
|
||||||
|
table class="table table-striped table-bordered table-white" style="width: 100%; margin: 0; table-layout:fixed;"
|
||||||
|
thead
|
||||||
|
th style="width: 50%" Worker
|
||||||
|
th style="width: 20%" Queue
|
||||||
|
th style="width: 20%" Next Run
|
||||||
|
th style="width: 10%" Actions
|
||||||
|
- @schedules.each do |worker, schedule|
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
= worker.name
|
||||||
|
td= worker.get_sidekiq_options['queue']
|
||||||
|
td
|
||||||
|
== relative_time(schedule.next_occurrence)
|
||||||
|
td
|
||||||
|
a href="#{root_path}sidetiq/#{worker.name}" Details
|
||||||
|
- else
|
||||||
|
.alert.alert-success No recurring jobs found.
|
||||||
|
|
40
lib/sidetiq/views/sidetiq_details.slim
Normal file
40
lib/sidetiq/views/sidetiq_details.slim
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
header.row
|
||||||
|
.span5
|
||||||
|
h3
|
||||||
|
' Recurring Job:
|
||||||
|
= @worker.name
|
||||||
|
|
||||||
|
- if (recurrences = @schedule.recurrence_rules).length > 0
|
||||||
|
table class="table table-striped table-bordered table-white" style="width: 100%; margin: 0; table-layout:fixed;"
|
||||||
|
thead
|
||||||
|
th Recurrences
|
||||||
|
- recurrences.each do |rule|
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
= rule.to_s
|
||||||
|
|
||||||
|
br
|
||||||
|
|
||||||
|
- if (exceptions = @schedule.exception_rules).length > 0
|
||||||
|
table class="table table-striped table-bordered table-white" style="width: 100%; margin: 0; table-layout:fixed;"
|
||||||
|
thead
|
||||||
|
th Exceptions
|
||||||
|
- exceptions.each do |rule|
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
= rule.to_s
|
||||||
|
|
||||||
|
br
|
||||||
|
|
||||||
|
table class="table table-striped table-bordered table-white" style="width: 100%; margin: 0; table-layout:fixed;"
|
||||||
|
thead
|
||||||
|
th style="width: 25%" Next 10 runs
|
||||||
|
th style="width: 75%"
|
||||||
|
- @schedule.next_occurrences(10).each do |time|
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
time= time.getutc
|
||||||
|
td
|
||||||
|
== relative_time(time)
|
||||||
|
|
||||||
|
br
|
42
lib/sidetiq/web.rb
Normal file
42
lib/sidetiq/web.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
require 'sidekiq/web'
|
||||||
|
|
||||||
|
module Sidetiq
|
||||||
|
module Web
|
||||||
|
|
||||||
|
def self.registered(app)
|
||||||
|
app.helpers do
|
||||||
|
def find_template(view, *args, &block)
|
||||||
|
path = File.expand_path(File.join('..', 'views'), __FILE__)
|
||||||
|
super(path, *args, &block)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
app.get "/sidetiq" do
|
||||||
|
@schedules = Sidetiq::Clock.instance.schedules
|
||||||
|
slim :sidetiq
|
||||||
|
end
|
||||||
|
|
||||||
|
app.get "/sidetiq/:name" do
|
||||||
|
halt 404 unless (name = params[:name])
|
||||||
|
|
||||||
|
schedules = Sidetiq::Clock.instance.schedules
|
||||||
|
|
||||||
|
@worker, @schedule = schedules.select do |worker, schedule|
|
||||||
|
worker.name == name
|
||||||
|
end.flatten
|
||||||
|
|
||||||
|
slim :sidetiq_details
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Sidekiq::Web.register(Sidetiq::Web)
|
||||||
|
|
||||||
|
if Sidekiq::Web.tabs.is_a?(Array)
|
||||||
|
Sidekiq::Web.tabs << "sidetiq"
|
||||||
|
else
|
||||||
|
Sidekiq::Web.tabs["Sidetiq"] = "sidetiq"
|
||||||
|
end
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
require 'simplecov'
|
require 'simplecov'
|
||||||
SimpleCov.start { add_filter "/test/" }
|
SimpleCov.start { add_filter "/test/" }
|
||||||
|
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
require 'mocha/setup'
|
require 'mocha/setup'
|
||||||
require 'sidetiq'
|
require 'rack/test'
|
||||||
|
|
||||||
|
require 'sidekiq'
|
||||||
require 'sidekiq/testing'
|
require 'sidekiq/testing'
|
||||||
|
|
||||||
|
require 'sidetiq'
|
||||||
|
require 'sidetiq/web'
|
||||||
|
|
||||||
# Stub out Clock#start! so we don't actually loop
|
# Stub out Clock#start! so we don't actually loop
|
||||||
module Sidetiq
|
module Sidetiq
|
||||||
class Clock
|
class Clock
|
||||||
|
|
62
test/test_web.rb
Normal file
62
test/test_web.rb
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
require_relative 'helper'
|
||||||
|
|
||||||
|
class TestWeb < MiniTest::Unit::TestCase
|
||||||
|
include Rack::Test::Methods
|
||||||
|
|
||||||
|
class Worker
|
||||||
|
include Sidekiq::Worker
|
||||||
|
include Sidetiq::Schedulable
|
||||||
|
|
||||||
|
tiq do
|
||||||
|
daily(1)
|
||||||
|
yearly(2)
|
||||||
|
monthly(3)
|
||||||
|
|
||||||
|
add_exception_rule yearly.month_of_year(:february)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def app
|
||||||
|
Sidekiq::Web
|
||||||
|
end
|
||||||
|
|
||||||
|
def clock
|
||||||
|
Sidetiq::Clock.instance
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_home_tab
|
||||||
|
get '/'
|
||||||
|
assert_equal 200, last_response.status
|
||||||
|
assert_match last_response.body, /Sidekiq/
|
||||||
|
assert_match last_response.body, /Sidetiq/
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sidetiq_page
|
||||||
|
get '/sidetiq'
|
||||||
|
assert_equal 200, last_response.status
|
||||||
|
|
||||||
|
clock.schedules.each do |worker, schedule|
|
||||||
|
assert_match last_response.body, /#{worker.name}/
|
||||||
|
assert_match last_response.body, /#{worker.get_sidekiq_options['queue']}/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_details_page
|
||||||
|
get "/sidetiq/#{Worker.name}"
|
||||||
|
assert_equal 200, last_response.status
|
||||||
|
schedule = clock.schedules[Worker]
|
||||||
|
|
||||||
|
schedule.recurrence_rules.each do |rule|
|
||||||
|
assert_match last_response.body, /#{rule.to_s}/
|
||||||
|
end
|
||||||
|
|
||||||
|
schedule.exception_rules.each do |rule|
|
||||||
|
assert_match last_response.body, /#{rule.to_s}/
|
||||||
|
end
|
||||||
|
|
||||||
|
schedule.next_occurrences(10).each do |time|
|
||||||
|
assert_match last_response.body, /#{time.getutc.to_s}/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue