Skip to content
Browse files

refactor a bit

  • Loading branch information...
1 parent 0a0cd82 commit 7e1e1c72004f356625b5928808ab23a2a1814018 @akshayrawat committed May 25, 2012
View
2 app/assets/javascripts/dj_mon.js
@@ -10,7 +10,7 @@ $(function(){
var dataUrl = tabContent.data('url');
$.getJSON(dataUrl).success(function(data){
- var template = $('#delayed_jobs_template').html();
+ var template = $('#dj_reports_template').html();
if(data.length > 0)
var output = Mustache.render(template, data);
else
View
38 app/controllers/dj_mon/delayed_jobs_controller.rb
@@ -1,38 +0,0 @@
-module DjMon
- class DelayedJobsController < ActionController::Base
- respond_to :json
- layout 'dj_mon'
-
- before_filter :authenticate
-
- def index
- @delayed_jobs = []
- end
-
- def all
- respond_with Delayed::Job.all
- end
-
- def failed
- respond_with Delayed::Job.where('delayed_jobs.failed_at IS NOT NULL')
- end
-
- def active
- respond_with Delayed::Job.where('delayed_jobs.locked_by IS NOT NULL')
- end
-
- def queued
- respond_with Delayed::Job.where('delayed_jobs.failed_at IS NULL AND delayed_jobs.locked_by IS NULL')
- end
-
- protected
-
- def authenticate
- authenticate_or_request_with_http_basic do |username, password|
- username == Rails.configuration.dj_mon.username &&
- password == Rails.configuration.dj_mon.password
- end
- end
- end
-
-end
View
42 app/controllers/dj_mon/dj_reports_controller.rb
@@ -0,0 +1,42 @@
+module DjMon
+ class DjReportsController < ActionController::Base
+ respond_to :json
+ layout 'dj_mon'
+
+ before_filter :authenticate
+
+ def index
+ end
+
+ def all
+ respond_with reports_for(Delayed::Job.all)
+ end
+
+ def failed
+ respond_with reports_for(Delayed::Job.where('delayed_jobs.failed_at IS NOT NULL'))
+ end
+
+ def active
+ respond_with reports_for(Delayed::Job.where('delayed_jobs.locked_by IS NOT NULL'))
+ end
+
+ def queued
+ respond_with reports_for(Delayed::Job.where('delayed_jobs.failed_at IS NULL AND delayed_jobs.locked_by IS NULL'))
+ end
+
+ protected
+
+ def authenticate
+ authenticate_or_request_with_http_basic do |username, password|
+ username == Rails.configuration.dj_mon.username &&
+ password == Rails.configuration.dj_mon.password
+ end
+ end
+
+ def reports_for jobs
+ jobs.collect { |job| DjReport.new(job) }
+ end
+
+ end
+
+end
View
26 app/models/dj_mon/dj_report.rb
@@ -0,0 +1,26 @@
+module DjMon
+ class DjReport
+ attr_accessor :delayed_job
+
+ def initialize delayed_job
+ self.delayed_job = delayed_job
+ end
+
+ def as_json(options={})
+ {
+ id: delayed_job.id,
+ priority: delayed_job.priority,
+ attempts: delayed_job.attempts,
+ queue: delayed_job.queue,
+ last_error: delayed_job.last_error,
+ failed_at: l_date(delayed_job.failed_at),
+ run_at: l_date(delayed_job.run_at),
+ created_at: l_date(delayed_job.created_at)
+ }
+ end
+
+ def l_date date
+ date.present? ? I18n.l(date) : ""
+ end
+ end
+end
View
12 ...views/dj_mon/delayed_jobs/index.html.haml → app/views/dj_mon/dj_reports/index.html.haml
@@ -12,13 +12,13 @@
= link_to "Active", "#active", "data-toggle" => "tab"
.tab-content
- .tab-pane#all.active{ 'data-url' => all_delayed_jobs_url }
- .tab-pane#failed{ 'data-url'=> failed_delayed_jobs_url }
- .tab-pane#active{ 'data-url'=> active_delayed_jobs_url }
- .tab-pane#queued{ 'data-url'=> queued_delayed_jobs_url }
+ .tab-pane#all.active{ 'data-url' => all_dj_reports_url }
+ .tab-pane#failed{ 'data-url'=> failed_dj_reports_url }
+ .tab-pane#active{ 'data-url'=> active_dj_reports_url }
+ .tab-pane#queued{ 'data-url'=> queued_dj_reports_url }
-%script#delayed_jobs_template{ :type=> "text/x-handlebars-template" }
- %table.table.table-striped#delayed-jobs-table
+%script#dj_reports_template{ :type=> "text/x-handlebars-template" }
+ %table.table.table-striped
%thead
%tr
%th
View
2 app/views/layouts/dj_mon.html.haml
@@ -9,7 +9,7 @@
.navbar.navbar-fixed-top
.navbar-inner
.container
- = link_to "DJ Mon", delayed_jobs_url, class: "brand"
+ = link_to "DJ Mon", dj_reports_url, class: "brand"
.container
= yield
View
4 config/routes.rb
@@ -1,6 +1,6 @@
DjMon::Engine.routes.draw do
- resources :delayed_jobs, :only=> [ :index ] do
+ resources :dj_reports, :only=> [ :index ] do
collection do
get :all
get :failed
@@ -9,5 +9,5 @@
end
end
- root :to => 'delayed_jobs#index', :as => :delayed_jobs
+ root :to => 'dj_reports#index'
end

0 comments on commit 7e1e1c7

Please sign in to comment.
Something went wrong with that request. Please try again.