Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the 'Enqueue all' button for Pending jobs optional #80

Merged
merged 3 commits into from May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.markdown
Expand Up @@ -75,6 +75,19 @@ Rails' will need to be configured to `config.action_dispatch.x_sendfile_header =

Lighty is more `X-Sendfile`, like [outlined](http://redmine.lighttpd.net/projects/1/wiki/X-LIGHTTPD-send-file) in their wiki.

Configuration
-------------

The following settings can be changed using the `.set` method in your configu.ru. For example:

```ruby
DelayedJobWeb.set(:allow_requeue_pending, false)
```

* **`allow_requeue_pending`** (default: `true`)

Controls whether the 'Enqueue all immediately' button is available on the list of Pending jobs. Hiding this button can be useful if you have jobs set to run in the future and you don't want to accidentally run them immediately.


Contributing
------------
Expand Down
16 changes: 12 additions & 4 deletions lib/delayed_job_web/application/app.rb
Expand Up @@ -9,6 +9,8 @@ class DelayedJobWeb < Sinatra::Base
set :public_folder, File.expand_path('../public', __FILE__)
set :views, File.expand_path('../views', __FILE__)

set :allow_requeue_pending, true

# Enable sessions so we can use CSRF protection
enable :sessions

Expand Down Expand Up @@ -106,6 +108,7 @@ def csrf_token_tag
get "/#{page}" do
@jobs = delayed_jobs(page.to_sym, @queues).order('created_at desc, id desc').offset(start).limit(per_page)
@all_jobs = delayed_jobs(page.to_sym, @queues)
@allow_requeue_pending = settings.allow_requeue_pending
erb page.to_sym
end
end
Expand All @@ -115,11 +118,16 @@ def csrf_token_tag
redirect back
end

%w(pending failed).each do |page|
post "/requeue/#{page}" do
delayed_jobs(page.to_sym, @queues).update_all(:run_at => Time.now, :failed_at => nil)
redirect back
post "/requeue/pending" do
if settings.allow_requeue_pending
delayed_jobs(:pending, @queues).update_all(:run_at => Time.now, :failed_at => nil)
end
redirect back
end

post "/requeue/failed" do
delayed_jobs(:failed, @queues).update_all(:run_at => Time.now, :failed_at => nil)
redirect back
end

post "/requeue/:id" do
Expand Down
10 changes: 6 additions & 4 deletions lib/delayed_job_web/application/views/pending.erb
@@ -1,9 +1,11 @@
<h1>Pending</h1>
<% if @jobs.any? %>
<form action="<%= u('requeue/pending') %>" method="POST">
<%= csrf_token_tag %>
<input type="submit" value="Enqueue All Immediately"></input>
</form>
<% if @allow_requeue_pending -%>
<form action="<%= u('requeue/pending') %>" method="POST">
<%= csrf_token_tag %>
<input type="submit" value="Enqueue All Immediately"></input>
</form>
<% end -%>
<% end %>
<p class="sub">
The list below contains jobs currently being processed.
Expand Down
21 changes: 21 additions & 0 deletions test/lib/delayed_job_web/application/test_app.rb
Expand Up @@ -52,6 +52,27 @@ def test_requeue_pending

end

def test_requeue_pending_with_requeue_pending_disallowed

app.set(:allow_requeue_pending, false)

dataset = Minitest::Mock.new
where = lambda { |criteria|
dataset
}

Time.stub(:now, time) do
Delayed::Job.stub(:where, where) do
post "/requeue/pending", request_data, rack_env
last_response.status.must_equal 302
end
end

# Expect dataset to not have received any method calls.
dataset.verify

end

def test_requeue_id
job = Minitest::Mock.new
job.expect(:update_attributes, nil, [:run_at => time, :failed_at => nil])
Expand Down