/delayed_jobs: add run, cancel, retry, delete actions.
This commit is contained in:
@@ -1,7 +1,41 @@
|
|||||||
class DelayedJobsController < ApplicationController
|
class DelayedJobsController < ApplicationController
|
||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json, :js
|
||||||
|
before_filter :admin_only, except: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@delayed_jobs = Delayed::Job.order("created_at desc").paginate(params[:page], :limit => params[:limit])
|
@delayed_jobs = Delayed::Job.order("created_at desc").paginate(params[:page], :limit => params[:limit])
|
||||||
respond_with(@delayed_jobs)
|
respond_with(@delayed_jobs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cancel
|
||||||
|
@job = Delayed::Job.find(params[:id])
|
||||||
|
if !@job.locked_at?
|
||||||
|
@job.fail!
|
||||||
|
end
|
||||||
|
respond_with(@job)
|
||||||
|
end
|
||||||
|
|
||||||
|
def retry
|
||||||
|
@job = Delayed::Job.find(params[:id])
|
||||||
|
if !@job.locked_at?
|
||||||
|
@job.update({failed_at: nil, attempts: 0}, without_protection: true)
|
||||||
|
end
|
||||||
|
respond_with(@job)
|
||||||
|
end
|
||||||
|
|
||||||
|
def run
|
||||||
|
@job = Delayed::Job.find(params[:id])
|
||||||
|
if !@job.locked_at?
|
||||||
|
@job.update(run_at: Time.now)
|
||||||
|
end
|
||||||
|
respond_with(@job)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@job = Delayed::Job.find(params[:id])
|
||||||
|
if !@job.locked_at?
|
||||||
|
@job.destroy
|
||||||
|
end
|
||||||
|
respond_with(@job)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
1
app/views/delayed_jobs/cancel.js.erb
Normal file
1
app/views/delayed_jobs/cancel.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
location.reload();
|
||||||
1
app/views/delayed_jobs/destroy.js.erb
Normal file
1
app/views/delayed_jobs/destroy.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
location.reload();
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<th>Last error</th>
|
<th>Last error</th>
|
||||||
<th>Failed at</th>
|
<th>Failed at</th>
|
||||||
<th>Run at</th>
|
<th>Run at</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -28,6 +29,19 @@
|
|||||||
<td class="col-expand"><%= job.last_error %></td>
|
<td class="col-expand"><%= job.last_error %></td>
|
||||||
<td><%= time_ago_in_words_tagged(job.failed_at) if job.failed_at %></td>
|
<td><%= time_ago_in_words_tagged(job.failed_at) if job.failed_at %></td>
|
||||||
<td><%= time_ago_in_words_tagged(job.run_at) %></td>
|
<td><%= time_ago_in_words_tagged(job.run_at) %></td>
|
||||||
|
<td>
|
||||||
|
<% if CurrentUser.is_admin? %>
|
||||||
|
<% if job.locked_at? %>
|
||||||
|
Running
|
||||||
|
<% elsif job.failed? %>
|
||||||
|
<%= link_to "Retry", retry_delayed_job_path(job), method: :put, remote: true %> |
|
||||||
|
<%= link_to "Delete", delayed_job_path(job), method: :delete, remote: true %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to "Run", run_delayed_job_path(job), method: :put, remote: true %> |
|
||||||
|
<%= link_to "Cancel", cancel_delayed_job_path(job), method: :put, remote: true %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
1
app/views/delayed_jobs/retry.js.erb
Normal file
1
app/views/delayed_jobs/retry.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
location.reload();
|
||||||
1
app/views/delayed_jobs/run.js.erb
Normal file
1
app/views/delayed_jobs/run.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
location.reload();
|
||||||
@@ -110,7 +110,13 @@ Rails.application.routes.draw do
|
|||||||
get :posts
|
get :posts
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :delayed_jobs, :only => [:index]
|
resources :delayed_jobs, :only => [:index, :destroy] do
|
||||||
|
member do
|
||||||
|
put :run
|
||||||
|
put :retry
|
||||||
|
put :cancel
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :dmails, :only => [:new, :create, :index, :show, :destroy] do
|
resources :dmails, :only => [:new, :create, :index, :show, :destroy] do
|
||||||
collection do
|
collection do
|
||||||
get :search
|
get :search
|
||||||
|
|||||||
Reference in New Issue
Block a user