Permalink
Browse files

Add base web extension with failures page and failures middleware

  • Loading branch information...
1 parent 6159f33 commit 3241a0e2483ba792737c8f568ad63f39ea5790c6 @mhfs committed Aug 21, 2012
View
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in sidekiq-failures.gemspec
gemspec
+
+# FIXME remove once tabs support is released
+gem "sidekiq", github: "mperham/sidekiq"
View
@@ -1,6 +1,18 @@
+require "sidekiq/web"
require "sidekiq/failures/version"
+require "sidekiq/failures/middleware"
+require "sidekiq/failures/web_extension"
module Sidekiq
module Failures
end
end
+
+Sidekiq::Web.register Sidekiq::Failures::WebExtension
+Sidekiq::Web.tabs << "Failures"
+
+Sidekiq.configure_server do |config|
+ config.server_middleware do |chain|
+ chain.add Sidekiq::Failures::Middleware
+ end
+end
@@ -0,0 +1,23 @@
+module Sidekiq
+ module Failures
+ class Middleware
+ def call(worker, msg, queue)
+ yield
+ rescue => e
+ data = {
+ :failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S %Z"),
+ :payload => msg,
+ :exception => e.class.to_s,
+ :error => e.to_s,
+ :backtrace => e.backtrace,
+ :worker => msg['class'],
+ :queue => queue
+ }
+
+ Sidekiq.redis {|conn| conn.rpush(:failed, Sidekiq.dump_json(data)) }
+
+ raise
+ end
+ end
+ end
+end
@@ -0,0 +1 @@
+h1 Failed Jobs
@@ -0,0 +1,20 @@
+module Sidekiq
+ module Failures
+ module WebExtension
+
+ def self.registered(app)
+ app.helpers do
+ def find_template(view, *a, &b)
+ dir = File.expand_path("../views/", __FILE__)
+ super(dir, *a, &b)
+ super
+ end
+ end
+
+ app.get "/failures" do
+ slim :failures
+ end
+ end
+ end
+ end
+end
View
@@ -15,6 +15,12 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = Sidekiq::Failures::VERSION
- gem.add_dependency "sidekiq"
+ # FIXME uncomment once tab support is released
+ # gem.add_dependency "sidekiq"
+ gem.add_dependency "slim"
+ gem.add_dependency "sinatra"
+ gem.add_dependency "sprockets"
+
gem.add_development_dependency "rake"
+ gem.add_development_dependency "rack-test"
end
View
@@ -2,4 +2,9 @@
require "minitest/spec"
require "minitest/mock"
+require "rack/test"
+
+require "sidekiq"
require "sidekiq-failures"
+
+REDIS = Sidekiq::RedisConnection.create(:url => "redis://localhost/15", :namespace => 'sidekiq_failures_test')
View
@@ -0,0 +1,30 @@
+require "test_helper"
+
+module Sidekiq
+ describe "WebExtension" do
+ include Rack::Test::Methods
+
+ def app
+ Sidekiq::Web
+ end
+
+ before do
+ Sidekiq.redis = REDIS
+ Sidekiq.redis {|c| c.flushdb }
+ end
+
+ it 'can display home with failures tab' do
+ get '/'
+
+ last_response.status.must_equal 200
+ last_response.body.must_match /Sidekiq is idle/
+ last_response.body.must_match /Failures/
+ end
+
+ it 'can display failures page' do
+ get '/failures'
+ last_response.status.must_equal 200
+ last_response.body.must_match /Failed Jobs/
+ end
+ end
+end

0 comments on commit 3241a0e

Please sign in to comment.