Merge pull request #3029 from evazion/feat-job-control
Add ability to start/stop delayed jobs.
This commit is contained in:
@@ -1,7 +1,41 @@
|
||||
class DelayedJobsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
respond_to :html, :xml, :json, :js
|
||||
before_filter :admin_only, except: [:index]
|
||||
|
||||
def index
|
||||
@delayed_jobs = Delayed::Job.order("created_at desc").paginate(params[:page], :limit => params[:limit])
|
||||
@delayed_jobs = Delayed::Job.order("run_at asc").paginate(params[:page], :limit => params[:limit])
|
||||
respond_with(@delayed_jobs)
|
||||
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
|
||||
|
||||
@@ -90,7 +90,11 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
def time_ago_in_words_tagged(time)
|
||||
raw time_tag(time_ago_in_words(time) + " ago", time)
|
||||
if time.past?
|
||||
raw time_tag(time_ago_in_words(time) + " ago", time)
|
||||
else
|
||||
raw time_tag("in " + distance_of_time_in_words(Time.now, time), time)
|
||||
end
|
||||
end
|
||||
|
||||
def compact_time(time)
|
||||
|
||||
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();
|
||||
@@ -1,42 +1,56 @@
|
||||
<h1>Delayed Jobs</h1>
|
||||
<div id="c-delayed-jobs">
|
||||
<div id="a-index">
|
||||
<h1>Delayed Jobs</h1>
|
||||
|
||||
<table class="striped" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<th>Handler</th>
|
||||
<% end %>
|
||||
<th>Attempts</th>
|
||||
<th>Priority</th>
|
||||
<th>Last error</th>
|
||||
<th>Run at</th>
|
||||
<th>Failed at</th>
|
||||
<th>Queue</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @delayed_jobs.each do |job| %>
|
||||
<tr>
|
||||
<td><%= job.id %></td>
|
||||
<td><%= raw print_name(job) %></td>
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<td><%= raw print_handler(job) %></td>
|
||||
<table class="striped autofit">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Queue</th>
|
||||
<th>Name</th>
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<th>Handler</th>
|
||||
<% end %>
|
||||
<th>Attempts</th>
|
||||
<th>Last error</th>
|
||||
<th>Failed at</th>
|
||||
<th>Run at</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @delayed_jobs.each do |job| %>
|
||||
<tr>
|
||||
<td><%= job.queue %></td>
|
||||
<td><%= raw print_name(job) %></td>
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<td class="col-expand"><%= raw print_handler(job) %></td>
|
||||
<% end %>
|
||||
<td><%= job.attempts %></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.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>
|
||||
<% end %>
|
||||
<td><%= job.attempts %></td>
|
||||
<td><%= job.priority %></td>
|
||||
<td><%= job.last_error %></td>
|
||||
<td><%= job.run_at %></td>
|
||||
<td><%= job.failed_at %></td>
|
||||
<td><%= job.queue %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= numbered_paginator(@delayed_jobs) %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Delayed Jobs - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= numbered_paginator(@delayed_jobs) %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Delayed Jobs - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
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();
|
||||
2
config/initializers/delayed_jobs.rb
Normal file
2
config/initializers/delayed_jobs.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
Delayed::Worker.default_queue_name = "default"
|
||||
Delayed::Worker.destroy_failed_jobs = false
|
||||
@@ -110,7 +110,13 @@ Rails.application.routes.draw do
|
||||
get :posts
|
||||
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
|
||||
collection do
|
||||
get :search
|
||||
|
||||
Reference in New Issue
Block a user