delayed_job_web 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of delayed_job_web might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd71bb47b1d7610aedae5d9bba05adb12fff3c3a
4
- data.tar.gz: ab1cfb631599bd2d1c4522842a8e0b75b7837d04
3
+ metadata.gz: 74a545eb43b23219f3650c32fb4ec8946f27af4c
4
+ data.tar.gz: 05713de94d0c7aaf2a7e25a54d0f93f12e671cd6
5
5
  SHA512:
6
- metadata.gz: 4734261d3b5dbdd57161388f5900686cd6f9a25df1caabfcb64c70ddd8c6a0ae8eb84ba05c02f8a03b8fd0ff10269f6f413f0e4b78103a1e4cf787b431be08dd
7
- data.tar.gz: c15a29804f5bde65ff4849508aaa16aa11f7fc9e78eb0028aac3d586d2b975fa823fbd3150be7d9b993534c2337d457b495f2e4f2d9c2ead3cbf97823f9bb77a
6
+ metadata.gz: 8904284f071219871077d63c9c52dcd5993ba53e0a33358216f4586be950bf4d085823dc9b9e233c45f7dc9de12917b0229d327796831f6bd4d33556b0a71842
7
+ data.tar.gz: 9068d6b51e167cf0af75bd902544a3e5de7d18c588acad02481ccd69023f4e784521ce1c6dc74d74d262d769416e4b16df697d9ac7fa27090d39cca4e18b9fad
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "delayed_job_web"
5
- s.version = "1.2.5"
5
+ s.version = "1.2.6"
6
6
 
7
7
  s.authors = ["Erick Schmitt"]
8
8
  s.date = "2014-01-29"
@@ -47,10 +47,9 @@ Gem::Specification.new do |s|
47
47
  s.require_paths = ["lib"]
48
48
  s.summary = "Web interface for delayed_job"
49
49
 
50
- s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
50
+ s.add_runtime_dependency(%q<sinatra>, [">= 1.4.4"])
51
51
  s.add_runtime_dependency(%q<activerecord>, ["> 3.0.0"])
52
52
  s.add_runtime_dependency(%q<delayed_job>, ["> 2.0.3"])
53
53
  s.add_development_dependency(%q<shoulda>, [">= 0"])
54
54
  s.add_development_dependency(%q<rack-test>, [">= 0"])
55
55
  end
56
-
@@ -6,9 +6,27 @@ require 'delayed_job'
6
6
  class DelayedJobWeb < Sinatra::Base
7
7
  set :root, File.dirname(__FILE__)
8
8
  set :static, true
9
- set :public_folder, File.expand_path('../public', __FILE__)
10
- set :views, File.expand_path('../views', __FILE__)
11
-
9
+ set :public_folder, File.expand_path('../public', __FILE__)
10
+ set :views, File.expand_path('../views', __FILE__)
11
+
12
+ # Enable sessions so we can use CSRF protection
13
+ set :sessions,
14
+ # Unique cookie key that won't clash with Rails etc
15
+ :key => "rack.delayed-job-web-session"
16
+
17
+ set :protection,
18
+ # Various session protections
19
+ :session => true,
20
+ # Various non-default Rack::Protection options
21
+ :use => [
22
+ # Prevent destructive actions without a valid CSRF auth token
23
+ :authenticity_token,
24
+ # Prevent destructive actions with remote referrers
25
+ :remote_referrer
26
+ ],
27
+ # Deny the request, don't clear the session
28
+ :reaction => :deny
29
+
12
30
  before do
13
31
  @queues = (params[:queues] || "").split(",").map{|queue| queue.strip}.uniq.compact
14
32
  end
@@ -24,13 +42,18 @@ class DelayedJobWeb < Sinatra::Base
24
42
  def per_page
25
43
  20
26
44
  end
27
-
45
+
28
46
  def url_path(*path_parts)
29
47
  url = [ path_prefix, path_parts ].join("/").squeeze('/')
30
48
  url += "?queues=#{@queues.join(",")}" unless @queues.empty?
31
49
  url
32
50
  end
33
- alias_method :u, :url_path
51
+
52
+ alias_method :u, :url_path
53
+
54
+ def h(text)
55
+ Rack::Utils.escape_html(text)
56
+ end
34
57
 
35
58
  def path_prefix
36
59
  request.env['SCRIPT_NAME']
@@ -55,6 +78,15 @@ class DelayedJobWeb < Sinatra::Base
55
78
  end
56
79
  end
57
80
 
81
+ def csrf_token
82
+ # Set up by Rack::Protection
83
+ session[:csrf]
84
+ end
85
+
86
+ def csrf_token_tag
87
+ "<input type='hidden' name='authenticity_token' value='#{h csrf_token}'>"
88
+ end
89
+
58
90
  get '/overview' do
59
91
  if delayed_job
60
92
  erb :overview
@@ -76,25 +108,25 @@ class DelayedJobWeb < Sinatra::Base
76
108
  end
77
109
  end
78
110
 
79
- get "/remove/:id" do
111
+ post "/remove/:id" do
80
112
  delayed_job.find(params[:id]).delete
81
113
  redirect back
82
114
  end
83
115
 
84
- get "/requeue/:id" do
116
+ post "/requeue/:id" do
85
117
  job = delayed_job.find(params[:id])
86
118
  job.update_attributes(:run_at => Time.now, :failed_at => nil)
87
119
  redirect back
88
120
  end
89
121
 
90
- get "/reload/:id" do
122
+ post "/reload/:id" do
91
123
  job = delayed_job.find(params[:id])
92
124
  job.update_attributes(:run_at => Time.now, :failed_at => nil, :locked_by => nil, :locked_at => nil, :last_error => nil, :attempts => 0)
93
125
  redirect back
94
126
  end
95
127
 
96
128
  post "/failed/clear" do
97
- delayed_job.destroy_all(delayed_job_sql(:failed, @queues))
129
+ delayed_jobs(:failed, @queues).delete_all
98
130
  redirect u('failed')
99
131
  end
100
132
 
@@ -104,24 +136,23 @@ class DelayedJobWeb < Sinatra::Base
104
136
  end
105
137
 
106
138
  def delayed_jobs(type, queues = [])
107
- delayed_job.where(delayed_job_sql(type, queues))
108
- end
109
-
110
- def delayed_job_sql(type, queues = [])
111
- conditions = []
112
-
113
- conditions << case type
114
- when :working
115
- 'locked_at is not null'
116
- when :failed
117
- 'last_error is not null'
118
- when :pending
119
- 'attempts = 0'
120
- end
121
-
122
- conditions << "queue IN ('#{queues.join("','")}')" unless queues.empty?
123
-
124
- conditions.compact.join(" AND ")
139
+ rel = delayed_job
140
+
141
+ rel =
142
+ case type
143
+ when :working
144
+ rel.where('locked_at IS NOT NULL')
145
+ when :failed
146
+ rel.where('last_error IS NOT NULL')
147
+ when :pending
148
+ rel.where(:attempts => 0)
149
+ else
150
+ rel
151
+ end
152
+
153
+ rel = rel.where(:queue => queues) unless queues.empty?
154
+
155
+ rel
125
156
  end
126
157
 
127
158
  get "/?" do
@@ -75,6 +75,7 @@ pre { font-family:Courier New; line-height:1.4em; }
75
75
  #main ul.job li dl dd .retried .remove { display:none; margin-top: 8px; }
76
76
  #main ul.job li.hover dl dd .retried .remove { display:block; }
77
77
  #main ul.job li dl dd .controls { display:none; float:right; }
78
+ #main ul.job li dl dd .controls form { display: inline; }
78
79
  #main ul.job li.hover dl dd .controls { display:block; }
79
80
  #main ul.job li dl dd code, #main ul.failed li dl dd pre { font-family:Monaco, "Courier New", monospace; font-size:90%; white-space: pre-wrap;}
80
81
  #main ul.job li dl dd.error a {font-family:Monaco, "Courier New", monospace; font-size:90%; }
@@ -84,6 +85,6 @@ pre { font-family:Courier New; line-height:1.4em; }
84
85
  #main p.pagination a.less { float:left;}
85
86
  #main p.pagination a.more { float:right;}
86
87
 
87
- #main form {float:right; margin-top:-10px;margin-left:10px;}
88
+ #main .header-queues {float:right; margin-top:-10px;margin-left:10px;}
88
89
 
89
90
  #main .time a.toggle_format {text-decoration:none;}
@@ -1,2 +1,2 @@
1
1
  <h1>Error</h1>
2
- <p><%= @message %></p>
2
+ <p><%=h @message %></p>
@@ -1,9 +1,11 @@
1
1
  <h1>Failed Jobs</h1>
2
2
  <% if @jobs.any? %>
3
3
  <form action="<%= u('failed/clear') %>" method="POST">
4
+ <%= csrf_token_tag %>
4
5
  <input type="submit" value="Clear Failed Jobs"></input>
5
6
  </form>
6
7
  <form action="<%= u('requeue/all') %>" method="POST">
8
+ <%= csrf_token_tag %>
7
9
  <input type="submit" value="Retry Failed Jobs"></input>
8
10
  </form>
9
11
  <% end %>
@@ -3,59 +3,62 @@
3
3
  <dt>ID</dt>
4
4
  <dd>
5
5
  <a name="<%= job.id %>"></a>
6
- <a href="#<%= job.id %>"><%= job.id %></a>
6
+ <a href="#<%= job.id %>"><%=h job.id %></a>
7
7
  <div class="controls">
8
- <a href="<%= u("requeue/#{job.id}") %>" rel="retry">Retry</a>
8
+ <form action="<%= u("requeue/#{job.id}") %>" method="post"><%= csrf_token_tag %><input type="submit" value="Retry"></input></form>
9
9
  or
10
- <a href="<%= u("remove/#{job.id}") %>" rel="remove">Remove</a>
10
+ <form action="<%= u("remove/#{job.id}") %>" method="post"><%= csrf_token_tag %><input type="submit" value="Remove"></input></form>
11
11
  or
12
- <a href="<%= u("reload/#{job.id}") %>" rel="reload_job">Reload Job</a>
12
+ <form action="<%= u("reload/#{job.id}") %>" method="post"><%= csrf_token_tag %><input type="submit" value="Reload"></input></form>
13
13
  </div>
14
14
  </dd>
15
15
  <dt>Priority</dt>
16
- <dd><%= job.priority %></dd>
16
+ <dd><%=h job.priority %></dd>
17
17
  <dt>Attempts</dt>
18
- <dd><%= job.attempts %></dd>
18
+ <dd><%=h job.attempts %></dd>
19
19
  <% if job.respond_to?(:queue) && job.queue %>
20
20
  <dt>Queue</dt>
21
- <dd><%= job.queue %></dd>
21
+ <dd><%=h job.queue %></dd>
22
22
  <% end %>
23
23
  <dt>Handler</dt>
24
24
  <dd>
25
- <pre><%= job.handler %></pre>
25
+ <pre><%=h job.handler %></pre>
26
26
  </dd>
27
27
  <% if job.last_error %>
28
28
  <dt>Last Error</dt>
29
29
  <dd>
30
30
  <div class="backtrace">
31
- <pre><%= job.last_error[0..100] + '...' %></pre>
31
+ <pre><%=h job.last_error[0..100] + '...' %></pre>
32
32
  </div>
33
33
  <a class="backtrace" href="#">Toggle full message</a>
34
34
  <div class="backtrace full hide">
35
- <pre><%= job.last_error %></pre>
35
+ <pre><%=h job.last_error %></pre>
36
36
  </div>
37
37
  </dd>
38
38
  <% end %>
39
39
  <% if job.run_at %>
40
40
  <dt>Run At</dt>
41
41
  <dd class="time">
42
- <%= job.run_at.rfc822 %>
42
+ <%=h job.run_at.rfc822 %>
43
43
  </dd>
44
44
  <% end %>
45
45
  <% if job.locked_at %>
46
46
  <dt>Locked At</dt>
47
47
  <dd class="time">
48
- <%= job.locked_at.rfc822 %>
48
+ <%=h job.locked_at.rfc822 %>
49
49
  </dd>
50
50
  <% end %>
51
51
  <% if job.locked_by %>
52
52
  <dt>Locked By</dt>
53
53
  <dd>
54
- <%= job.locked_by %>
54
+ <%=h job.locked_by %>
55
55
  </dd>
56
56
  <% end %>
57
57
  <% if job.failed_at %>
58
58
  <dt>Failed At</dt>
59
+ <dd>
60
+ <%=h job.failed_at %>
61
+ </dd>
59
62
  <% end %>
60
63
  </dl>
61
64
  </li>
@@ -11,13 +11,13 @@
11
11
  <% tabs.each do |tab| %>
12
12
  <li class="<%= request.path_info == tab[:path] ? 'current' : '' %>">
13
13
  <a class="tab" href="<%= u(tab[:path]) %>">
14
- <%= tab[:name] %>
14
+ <%=h tab[:name] %>
15
15
  </a>
16
16
  </li>
17
17
  <% end %>
18
18
  <li>
19
- <form method="get" action="" style="display:inline; width: 100%;">
20
- <input name="queues" type="text" value="<%= @queues.join(", ") %>" style="width: 300px;" placeholder="Filter jobs by queue name (e.g. queue1, queue2)" />
19
+ <form method="get" class="header-queues" action="" style="display:inline; width: 100%;">
20
+ <input name="queues" type="text" value="<%=h @queues.join(", ") %>" style="width: 300px;" placeholder="Filter jobs by queue name (e.g. queue1, queue2)" />
21
21
  <input type="submit" value="Filter" />
22
22
  </form>
23
23
  </li>
@@ -30,7 +30,7 @@
30
30
  <p>
31
31
  Powered by
32
32
  <a href="https://github.com/collectiveidea/delayed_job">delayed_job</a>
33
- &
33
+ &amp;
34
34
  <a href="https://github.com/ejschmitt/delayed_job_web">delayed_job_web</a>
35
35
  </p>
36
36
  </div>
@@ -1,6 +1,7 @@
1
1
  <h1>Pending</h1>
2
2
  <% if @jobs.any? %>
3
3
  <form action="<%= u('requeue/all') %>" method="POST">
4
+ <%= csrf_token_tag %>
4
5
  <input type="submit" value="Enqueue All Immediately"></input>
5
6
  </form>
6
7
  <% end %>
@@ -5,7 +5,7 @@
5
5
  environment
6
6
  </th>
7
7
  <th>
8
- <%= Sinatra::Application.environment.to_s %>
8
+ <%=h Sinatra::Application.environment.to_s %>
9
9
  </th>
10
10
  </tr>
11
11
  <tr>
@@ -26,6 +26,10 @@ class Delayed::Job
26
26
  def self.count(*args)
27
27
  0
28
28
  end
29
+
30
+ def self.order(*args)
31
+ DelayedJobFake.new
32
+ end
29
33
  end
30
34
 
31
35
  class TestDelayedJobWeb < Test::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_web
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erick Schmitt
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.2
19
+ version: 1.4.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.2
26
+ version: 1.4.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement