dj_mon 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,7 @@
1
- # DJ Mon
1
+ # DJ Mon [![Build Status](https://secure.travis-ci.org/akshayrawat/dj_mon.png)](http://travis-ci.org/akshayrawat/dj_mon)
2
2
 
3
3
  A Rails engine based frontend for Delayed Job.
4
4
 
5
- ## Demo
6
- * [Demo URL](http://dj-mon-demo.herokuapp.com/)
7
- * Username: `dj_mon`
8
- * Password: `password`
9
- * [Demo Source](https://github.com/akshayrawat/dj_mon_demo)
10
-
11
-
12
5
  ## Installation
13
6
 
14
7
  Add this line to your application's Gemfile:
@@ -24,7 +17,8 @@ Or install it yourself as:
24
17
  $ gem install dj_mon
25
18
 
26
19
  ## Note
27
- Supports only `activerecord` for now.
20
+
21
+ Supports only `activerecord` and `mongoid` for now.
28
22
 
29
23
  ## Usage
30
24
 
@@ -45,16 +39,23 @@ If the credentials are not set, then the username and password are assumed to be
45
39
 
46
40
  Now visit `http://localhost:3000/dj_mon` and profit!
47
41
 
42
+
48
43
  ## Demo
49
- * Source [DJ Mon](https://github.com/akshayrawat/dj_mon)
50
- * URL: [Demo](http://dj-mon-demo.herokuapp.com/)
44
+
45
+ * [Demo URL](http://dj-mon-demo.herokuapp.com/)
51
46
  * Username: `dj_mon`
52
- * Password: `password`
47
+ * Password: `password`
48
+ * [Demo Source](https://github.com/akshayrawat/dj_mon_demo)
49
+
50
+ ![Screenshot](https://github.com/akshayrawat/dj_mon_demo/raw/master/docs/screenshot.jpg)
51
+
52
+
53
+ ## Running the test suite
53
54
 
54
- ## Contributing
55
+ To run the test suite, execute the following commands on the project
56
+ root:
55
57
 
56
- 1. Fork it
57
- 2. Create your feature branch (`git checkout -b my-new-feature`)
58
- 3. Commit your changes (`git commit -am 'Added some feature'`)
59
- 4. Push to the branch (`git push origin my-new-feature`)
60
- 5. Create new Pull Request
58
+ gem install bundler
59
+ bundle install
60
+ rake test:prepare
61
+ rake
data/Rakefile CHANGED
@@ -7,18 +7,38 @@ rescue LoadError
7
7
  end
8
8
 
9
9
  require 'rake'
10
- require 'rake/rdoctask'
10
+ require 'rdoc/task'
11
11
 
12
12
  require 'rake/testtask'
13
13
 
14
- Rake::TestTask.new(:test) do |t|
15
- t.libs << 'lib'
16
- t.libs << 'test'
17
- t.pattern = 'test/**/*_test.rb'
18
- t.verbose = false
14
+ namespace :test do
15
+
16
+ desc "Run all tests for the ActiveRecord backend"
17
+ Rake::TestTask.new(:active_record) do |t|
18
+ t.pattern = 'test/**/*_test.rb'
19
+ t.libs = [ "test/dummy_active_record" ]
20
+ end
21
+
22
+ desc "Run all tests for the Mongoid backend"
23
+ Rake::TestTask.new(:mongoid) do |t|
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.libs = [ "test/dummy_mongoid" ]
26
+ end
27
+
28
+ desc "Runs all tests"
29
+ task "all"=> [ :active_record, :mongoid ]
30
+
31
+ desc "Prepare environment for tests"
32
+ task :prepare do
33
+ FileUtils.cd File.expand_path("../test/dummy_active_record", __FILE__)
34
+ system("rake db:create:all")
35
+ system("rake db:migrate")
36
+ system("rake db:test:clone")
37
+ end
38
+
19
39
  end
20
40
 
21
- task :default => :test
41
+ task default: 'test:all'
22
42
 
23
43
  Rake::RDocTask.new(:rdoc) do |rdoc|
24
44
  rdoc.rdoc_dir = 'rdoc'
@@ -27,3 +47,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
27
47
  rdoc.rdoc_files.include('README.rdoc')
28
48
  rdoc.rdoc_files.include('lib/**/*.rb')
29
49
  end
50
+
@@ -39,7 +39,7 @@ $(function(){
39
39
  });
40
40
 
41
41
  (function refreshCount() {
42
- $.getJSON('/dj_mon/dj_reports/dj_counts/').success(function(data){
42
+ $.getJSON(dj_counts_dj_reports_url).success(function(data){
43
43
  var template = $('#dj_counts_template').html();
44
44
  var output = Mustache.render(template, data);
45
45
  $('#dj-counts-view').html(output);
@@ -4,6 +4,15 @@ body {
4
4
  padding: 90px;
5
5
  }
6
6
 
7
+ .container {
8
+ width: 980px;
9
+ }
10
+
11
+ .navbar .btn#settings {
12
+ margin: 8px 5px 5px;
13
+ padding: 1px 10px 1px;
14
+ }
15
+
7
16
  table#jobs-table td, table#jobs-table th {
8
17
  text-align: center;
9
18
  }
@@ -38,4 +47,4 @@ code.block {
38
47
 
39
48
  form.form-inline {
40
49
  display: inline;
41
- }
50
+ }
@@ -1,9 +1,10 @@
1
1
  module DjMon
2
2
  class DjReportsController < ActionController::Base
3
- respond_to :json
3
+ respond_to :json, :html
4
4
  layout 'dj_mon'
5
-
5
+
6
6
  before_filter :authenticate
7
+ after_filter :set_api_version
7
8
 
8
9
  def index
9
10
  end
@@ -23,27 +24,31 @@ module DjMon
23
24
  def queued
24
25
  respond_with DjReport.queued_reports
25
26
  end
26
-
27
+
27
28
  def dj_counts
28
29
  respond_with DjReport.dj_counts
29
30
  end
30
-
31
+
31
32
  def settings
32
33
  respond_with DjReport.settings
33
34
  end
34
-
35
+
35
36
  def retry
36
- dj = Delayed::Job.find(params[:id])
37
- dj.update_attribute :failed_at, nil if dj
38
- redirect_to root_url, notice: "The job was been queued for a re-run" and return
37
+ DjMon::Backend.retry params[:id]
38
+ respond_to do |format|
39
+ format.html { redirect_to root_url, notice: "The job has been queued for a re-run" and return }
40
+ format.json { head(:ok) }
41
+ end
39
42
  end
40
-
43
+
41
44
  def destroy
42
- dj = Delayed::Job.find(params[:id])
43
- dj.destroy if dj
44
- redirect_to root_url, notice: "The job was deleted" and return
45
+ DjMon::Backend.destroy params[:id]
46
+ respond_to do |format|
47
+ format.html { redirect_to root_url, notice: "The job was deleted" and return }
48
+ format.json { head(:ok) }
49
+ end
45
50
  end
46
-
51
+
47
52
  protected
48
53
 
49
54
  def authenticate
@@ -52,6 +57,11 @@ module DjMon
52
57
  password == Rails.configuration.dj_mon.password
53
58
  end
54
59
  end
60
+
61
+ def set_api_version
62
+ response.headers['DJ-Mon-Version'] = DjMon::VERSION
63
+ end
64
+
55
65
  end
56
66
 
57
67
  end
@@ -1,5 +1,6 @@
1
1
  module DjMon
2
2
  class DjReport
3
+ TIME_FORMAT = "%b %d %H:%M:%S"
3
4
 
4
5
  attr_accessor :delayed_job
5
6
 
@@ -10,7 +11,7 @@ module DjMon
10
11
  def as_json(options={})
11
12
  {
12
13
  id: delayed_job.id,
13
- payload: delayed_job.payload_object.object.to_yaml,
14
+ payload: payload(delayed_job),
14
15
  priority: delayed_job.priority,
15
16
  attempts: delayed_job.attempts,
16
17
  queue: delayed_job.queue || "global",
@@ -23,49 +24,37 @@ module DjMon
23
24
  }
24
25
  end
25
26
 
26
- class << self
27
-
28
- def all
29
- Delayed::Job.all
30
- end
31
-
32
- def failed
33
- Delayed::Job.where('delayed_jobs.failed_at IS NOT NULL')
34
- end
35
-
36
- def active
37
- Delayed::Job.where('delayed_jobs.failed_at IS NULL AND delayed_jobs.locked_by IS NOT NULL')
38
- end
39
-
40
- def queued
41
- Delayed::Job.where('delayed_jobs.failed_at IS NULL AND delayed_jobs.locked_by IS NULL')
42
- end
27
+ def payload job
28
+ job.payload_object.respond_to?(:object) ? job.payload_object.object.to_yaml : job.payload_object.to_yaml
29
+ end
43
30
 
31
+ class << self
44
32
  def reports_for jobs
45
33
  jobs.collect { |job| DjReport.new(job) }
46
34
  end
47
35
 
48
36
  def all_reports
49
- reports_for all
37
+ reports_for DjMon::Backend.all
50
38
  end
51
39
 
52
40
  def failed_reports
53
- reports_for failed
41
+ reports_for DjMon::Backend.failed
54
42
  end
55
43
 
56
44
  def active_reports
57
- reports_for active
45
+ reports_for DjMon::Backend.active
58
46
  end
59
47
 
60
48
  def queued_reports
61
- reports_for queued
49
+ reports_for DjMon::Backend.queued
62
50
  end
63
51
 
64
52
  def dj_counts
65
53
  {
66
- failed: failed.size,
67
- active: active.size,
68
- queued: queued.size
54
+ all: DjMon::Backend.all.size,
55
+ failed: DjMon::Backend.failed.size,
56
+ active: DjMon::Backend.active.size,
57
+ queued: DjMon::Backend.queued.size
69
58
  }
70
59
  end
71
60
 
@@ -76,14 +65,16 @@ module DjMon
76
65
  max_attempts: Delayed::Worker.max_attempts,
77
66
  max_run_time: Delayed::Worker.max_run_time,
78
67
  read_ahead: Delayed::Worker.read_ahead,
79
- delay_jobs: Delayed::Worker.delay_jobs
68
+ delay_jobs: Delayed::Worker.delay_jobs,
69
+ delayed_job_version: Gem.loaded_specs["delayed_job"].version.version,
70
+ dj_mon_version: DjMon::VERSION
80
71
  }
81
72
  end
82
73
  end
83
74
 
84
75
  private
85
- def l_datetime date
86
- date.present? ? I18n.l(date) : ""
76
+ def l_datetime time
77
+ time.present? ? time.strftime(TIME_FORMAT) : ""
87
78
  end
88
79
  end
89
80
 
@@ -58,10 +58,10 @@
58
58
  {{#failed}}
59
59
  {{failed_at}}
60
60
 
61
- = form_tag '/dj_mon/dj_reports/{{id}}/retry', method: :post, class: 'form-inline' do
61
+ = form_tag CGI.unescape(retry_dj_report_url(:id => "{{id}}")), method: :post, class: 'form-inline' do
62
62
  = submit_tag 'Retry', class: 'btn btn-info btn-mini'
63
63
 
64
- = form_tag '/dj_mon/dj_reports/{{id}}', method: :delete, class: 'form-inline' do
64
+ = form_tag CGI.unescape(dj_report_url(:id => "{{id}}")), method: :delete, class: 'form-inline' do
65
65
  = submit_tag 'Delete', class: 'btn btn-danger btn-mini'
66
66
 
67
67
  {{/failed}}
@@ -16,8 +16,8 @@
16
16
 
17
17
  .pull-right
18
18
  #dj-counts-view
19
-
20
- .container
19
+
20
+ .container.centered
21
21
  - if flash[:notice]
22
22
  .alert.alert-success
23
23
  = flash[:notice]
@@ -26,15 +26,19 @@
26
26
  = yield
27
27
 
28
28
  = javascript_include_tag "//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
29
- = javascript_include_tag "dj_mon.js"
29
+ = javascript_include_tag "dj_mon"
30
+ %script
31
+ var dj_counts_dj_reports_url = "#{dj_counts_dj_reports_url}"
30
32
 
31
33
  %script#dj_counts_template{ :type=> "text/x-handlebars-template" }
32
- %span.badge
34
+ %span.badge.badge-warning
35
+ {{failed}} failed
36
+ %span.badge.badge-info
33
37
  {{queued}} queued
34
38
  %span.badge.badge-info
35
39
  {{active}} active
36
- %span.badge.badge-warning
37
- {{failed}} failed
40
+ %span.badge.badge-info
41
+ {{all}} all
38
42
 
39
43
  %script#dj_settings_template{ :type=> "text/x-handlebars-template" }
40
44
  .modal.hide
@@ -42,37 +46,47 @@
42
46
  %button{ type: "button", class: "close", 'data-dismiss' => "modal" }
43
47
  ×
44
48
  %h3
45
- Delayed Job Settings
49
+ Settings
46
50
  .modal-body
47
51
  %table.table.table-bordered.table-striped
48
52
  %tr
49
53
  %td
50
- Destroy failed jobs:
54
+ Delayed Job version
55
+ %td
56
+ <code>{{content.delayed_job_version}}</code>
57
+ %tr
58
+ %td
59
+ DJ Mon version
60
+ %td
61
+ <code>{{content.dj_mon_version}}</code>
62
+ %tr
63
+ %td
64
+ Destroy failed jobs
51
65
  %td
52
66
  <code>{{content.destroy_failed_jobs}}</code>
53
67
  %tr
54
68
  %td
55
- Sleep delay:
69
+ Sleep delay
56
70
  %td
57
71
  <code>{{content.sleep_delay}}</code> seconds
58
72
  %tr
59
73
  %td
60
- Max attempts:
74
+ Max attempts
61
75
  %td
62
76
  <code>{{content.max_attempts}}</code>
63
77
  %tr
64
78
  %td
65
- Max run time:
79
+ Max run time
66
80
  %td
67
81
  <code>{{content.max_run_time}}</code> seconds
68
82
  %tr
69
83
  %td
70
- Read ahead:
84
+ Read ahead
71
85
  %td
72
86
  <code>{{content.read_ahead}}</code>
73
87
  %tr
74
88
  %td
75
- Delay Jobs:
89
+ Delay Jobs
76
90
  %td
77
91
  <code>{{content.delay_jobs}}</code>
78
92
 
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  DjMon::Engine.routes.draw do
2
-
2
+
3
3
  resources :dj_reports do
4
4
  collection do
5
5
  get :all
@@ -0,0 +1,33 @@
1
+ module DjMon
2
+ module Backend
3
+ module ActiveRecord
4
+ class << self
5
+ def all
6
+ Delayed::Job.all
7
+ end
8
+
9
+ def failed
10
+ Delayed::Job.where('delayed_jobs.failed_at IS NOT NULL')
11
+ end
12
+
13
+ def active
14
+ Delayed::Job.where('delayed_jobs.failed_at IS NULL AND delayed_jobs.locked_by IS NOT NULL')
15
+ end
16
+
17
+ def queued
18
+ Delayed::Job.where('delayed_jobs.failed_at IS NULL AND delayed_jobs.locked_by IS NULL')
19
+ end
20
+
21
+ def destroy id
22
+ dj = Delayed::Job.find(id)
23
+ dj.destroy if dj
24
+ end
25
+
26
+ def retry id
27
+ dj = Delayed::Job.find(id)
28
+ dj.update_attributes({ failed_at: nil }) if dj
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module DjMon
2
+ module Backend
3
+ module Mongoid
4
+ class << self
5
+ def all
6
+ Delayed::Job.all
7
+ end
8
+
9
+ def failed
10
+ Delayed::Job.where(:failed_at.ne => nil)
11
+ end
12
+
13
+ def active
14
+ Delayed::Job.where(:failed_at => nil, :locked_by.ne => nil)
15
+ end
16
+
17
+ def queued
18
+ Delayed::Job.where(:failed_at => nil, :locked_by => nil)
19
+ end
20
+
21
+ def destroy id
22
+ dj = Delayed::Job.find(id)
23
+ dj.destroy if dj
24
+ end
25
+
26
+ def retry id
27
+ dj = Delayed::Job.find(id)
28
+ dj.update_attribute :failed_at, nil if dj
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module DjMon
2
+ module Backend
3
+ BACKEND_METHODS = [:all, :failed, :active, :queued, :destroy, :retry]
4
+
5
+ class << self
6
+ def used_backend
7
+ # it's hacky but, based on Delayed::Worker.backend= behavior
8
+ @@used_backend ||= begin
9
+ delayed_job_backend = Delayed::Worker.backend
10
+ backend_name = delayed_job_backend.to_s.split("::")[-2]
11
+ require "dj_mon/backend/#{backend_name.downcase}"
12
+ "DjMon::Backend::#{backend_name}".constantize
13
+ rescue
14
+ raise "DjMon has no backend for '#{delayed_job_backend}'"
15
+ end
16
+ end
17
+
18
+ delegate *BACKEND_METHODS, :to => :used_backend
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module DjMon
2
+ VERSION = "0.1.3".freeze
3
+ end
data/lib/dj_mon.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'haml'
2
2
  require 'dj_mon/engine'
3
+ require 'dj_mon/backend'
3
4
 
4
5
  module DjMon
5
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dj_mon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-01 00:00:00.000000000 Z
12
+ date: 2012-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -43,6 +43,70 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '3.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: delayed_job_active_record
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: delayed_job_mongoid
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: shoulda
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
46
110
  description: A Rails engine based frontend for Delayed Job
47
111
  email:
48
112
  - projects@akshay.cc
@@ -62,14 +126,18 @@ files:
62
126
  - app/models/dj_mon/dj_report.rb
63
127
  - app/views/dj_mon/dj_reports/index.html.haml
64
128
  - app/views/layouts/dj_mon.html.haml
129
+ - lib/dj_mon/backend/activerecord.rb
130
+ - lib/dj_mon/backend/mongoid.rb
131
+ - lib/dj_mon/backend.rb
65
132
  - lib/dj_mon/engine.rb
133
+ - lib/dj_mon/version.rb
66
134
  - lib/dj_mon.rb
67
135
  - config/routes.rb
68
136
  - MIT-LICENSE
69
137
  - Rakefile
70
138
  - Gemfile
71
139
  - README.md
72
- homepage: http://portfolio.akshay.cc/dj_mon/
140
+ homepage: https://github.com/akshayrawat/dj_mon
73
141
  licenses: []
74
142
  post_install_message:
75
143
  rdoc_options: []