-
Notifications
You must be signed in to change notification settings - Fork 482
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
Switch to minitest and convert the server to a Rails engine to match new plugins structure for Resque-Web #464
Open
mattgibson
wants to merge
32
commits into
resque:master
Choose a base branch
from
mattgibson:switch-to-minitest-and-convert-to-engine
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9d025a9
Converted syntax to Minitest spec. Lots of ordering failures.
mattgibson 85a7a2a
Fix broken env test and add a missing call to require test_helper
mattgibson 5ba39c4
Fixed some tests
mattgibson 928d1de
Moved the resetting stuff into a function that is called before every…
mattgibson 727340f
Remove TODOs
mattgibson 4de9e14
Fix comment
mattgibson 72c1aae
Dummy Rails app loads. Tests all pass.
mattgibson 8a89518
Remove mintest-bisect
mattgibson 8164d2d
DB for dummy app
mattgibson 6b72766
Ignore logs in the dummy app
mattgibson 2f1f93b
Directory path in .gitignore
mattgibson 8c320aa
Failing test for the presence of the schedule tab
mattgibson 59290e0
Basic transfer of server content to new engine
mattgibson 27cbfc5
Scheduler page tests work
mattgibson 846ff94
Add all routes to engine file and fix tabs
mattgibson 6218011
Tests for the delayed page and the job class page
mattgibson d44cc20
Working delayed and delayed job class pages
mattgibson b9711fa
Added tests and code up to requeue_with_params
mattgibson 0c973d6
Delayed search
mattgibson 28fd1f7
Cancel now path
mattgibson 4f8e39a
Clear path
mattgibson c9a734f
Queue now path
mattgibson fc22491
Timestamp path
mattgibson 0db7b46
Delete schedule when dynamic
mattgibson aa9f6c8
Delete when static
mattgibson 428936d
Fix tests
mattgibson e1d61eb
Remove hardcoded paths from views
mattgibson 0c7db2e
Remove old server
mattgibson 6cff910
Make Rubocop happy
mattgibson d46ed7d
Add classes to tables
mattgibson 4265204
Styling
mattgibson c4f436f
Styling
mattgibson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ nbproject | |
|
||
.env | ||
.env.* | ||
|
||
/test/dummy/log/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# vim:fileencoding=utf-8 | ||
require_relative 'resque/scheduler' | ||
require 'resque/scheduler/engine' | ||
|
||
Resque.extend Resque::Scheduler::Extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'resque_web' | ||
|
||
module ResqueWeb | ||
module Plugins | ||
module ResqueScheduler | ||
class Engine < Rails::Engine | ||
isolate_namespace ResqueWeb::Plugins::ResqueScheduler | ||
paths['app'] << 'lib/resque/scheduler/engine/app' | ||
paths['app/helpers'] << 'lib/resque/scheduler/engine/app/helpers' | ||
paths['app/views'] << 'lib/resque/scheduler/engine/app/views' | ||
paths['app/controllers'] << 'lib/resque/scheduler/'\ | ||
'engine/app/controllers' | ||
end | ||
|
||
Engine.routes do | ||
get 'schedule', to: 'schedules#index', as: 'schedules' | ||
post 'schedule/requeue', to: 'schedules#requeue', as: 'requeue' | ||
post 'schedule/requeue_with_params', | ||
to: 'schedules#requeue_with_params', | ||
as: 'requeue_with_params' | ||
delete 'schedule', to: 'schedules#destroy', as: 'schedule' | ||
|
||
get 'delayed', to: 'delayed#index', as: 'delayed' | ||
get 'delayed/jobs/:klass', | ||
to: 'delayed#jobs_klass', | ||
as: 'delayed_job_class' | ||
post 'delayed/search', to: 'delayed#search', as: 'delayed_search' | ||
get 'delayed/:timestamp', to: 'delayed#timestamp', as: 'timestamp' | ||
post 'delayed/queue_now', to: 'delayed#queue_now', as: 'queue_now' | ||
post 'delayed/cancel_now', to: 'delayed#cancel_now', as: 'cancel_now' | ||
post '/delayed/clear', to: 'delayed#clear', as: 'clear' | ||
end | ||
|
||
def self.engine_path | ||
'/scheduler' | ||
end | ||
|
||
def self.tabs | ||
[ | ||
{ | ||
'schedule' => Engine.app.url_helpers.schedules_path, | ||
'delayed' => Engine.app.url_helpers.delayed_path | ||
} | ||
] | ||
end | ||
end | ||
end | ||
end |
100 changes: 100 additions & 0 deletions
100
...cheduler/engine/app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
module ResqueWeb | ||
module Plugins | ||
module ResqueScheduler | ||
class DelayedController < ResqueWeb::ApplicationController | ||
def index | ||
end | ||
|
||
def jobs_klass | ||
klass = Resque::Scheduler::Util.constantize(params[:klass]) | ||
@args = JSON.load(URI.decode(params[:args])) | ||
@timestamps = Resque.scheduled_at(klass, *@args) | ||
rescue | ||
@timestamps = [] | ||
end | ||
|
||
def search | ||
@jobs = find_job(params[:search]) | ||
end | ||
|
||
def cancel_now | ||
klass = Resque::Scheduler::Util.constantize(params['klass']) | ||
timestamp = params['timestamp'] | ||
args = Resque.decode params['args'] | ||
Resque.remove_delayed_job_from_timestamp(timestamp, klass, *args) | ||
redirect_to Engine.app.url_helpers.delayed_path | ||
end | ||
|
||
def clear | ||
Resque.reset_delayed_queue | ||
redirect_to Engine.app.url_helpers.delayed_path | ||
end | ||
|
||
def queue_now | ||
timestamp = params['timestamp'].to_i | ||
if timestamp > 0 | ||
Resque::Scheduler.enqueue_delayed_items_for_timestamp(timestamp) | ||
end | ||
redirect_to ResqueWeb::Engine.app.url_helpers.overview_path | ||
end | ||
|
||
def timestamp | ||
@timestamp = params[:timestamp].to_i | ||
end | ||
|
||
protected | ||
|
||
def find_job(worker) | ||
worker = worker.downcase | ||
results = working_jobs_for_worker(worker) | ||
|
||
dels = delayed_jobs_for_worker(worker) | ||
results += dels.select do |j| | ||
j['class'].downcase.include?(worker) && | ||
j.merge!('where_at' => 'delayed') | ||
end | ||
|
||
Resque.queues.each do |queue| | ||
queued = Resque.peek(queue, 0, Resque.size(queue)) | ||
queued = [queued] unless queued.is_a?(Array) | ||
results += queued.select do |j| | ||
j['class'].downcase.include?(worker) && | ||
j.merge!('queue' => queue, 'where_at' => 'queued') | ||
end | ||
end | ||
|
||
results | ||
end | ||
|
||
def working_jobs_for_worker(worker) | ||
[].tap do |results| | ||
working = [*Resque.working] | ||
work = working.select do |w| | ||
w.job && w.job['payload'] && | ||
w.job['payload']['class'].downcase.include?(worker) | ||
end | ||
work.each do |w| | ||
results += [ | ||
w.job['payload'].merge( | ||
'queue' => w.job['queue'], 'where_at' => 'working' | ||
) | ||
] | ||
end | ||
end | ||
end | ||
|
||
def delayed_jobs_for_worker(_worker) | ||
[].tap do |dels| | ||
schedule_size = Resque.delayed_queue_schedule_size | ||
Resque.delayed_queue_peek(0, schedule_size).each do |d| | ||
Resque.delayed_timestamp_peek( | ||
d, 0, Resque.delayed_timestamp_size(d)).each do |j| | ||
dels << j.merge!('timestamp' => d) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
50 changes: 50 additions & 0 deletions
50
...eduler/engine/app/controllers/resque_web/plugins/resque_scheduler/schedules_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module ResqueWeb | ||
module Plugins | ||
module ResqueScheduler | ||
class SchedulesController < ResqueWeb::ApplicationController | ||
def index | ||
Resque.reload_schedule! if Resque::Scheduler.dynamic | ||
end | ||
|
||
def destroy | ||
if Resque::Scheduler.dynamic | ||
job_name = params['job_name'] || params[:job_name] | ||
Resque.remove_schedule(job_name) | ||
end | ||
redirect_to Engine.app.url_helpers.schedules_path | ||
end | ||
|
||
def requeue | ||
@job_name = params['job_name'] || params[:job_name] | ||
config = Resque.schedule[@job_name] | ||
@parameters = config['parameters'] || config[:parameters] | ||
if @parameters | ||
render 'requeue-params' | ||
else | ||
Resque::Scheduler.enqueue_from_config(config) | ||
redirect_to ResqueWeb::Engine.app.url_helpers.overview_path | ||
end | ||
end | ||
|
||
def requeue_with_params | ||
job_name = params['job_name'] || params[:job_name] | ||
config = Resque.schedule[job_name] | ||
# Build args hash from post data (removing the job name) | ||
submitted_args = params.reject do |key, _value| | ||
%w(job_name action controller).include?(key) | ||
end | ||
|
||
# Merge constructed args hash with existing args hash for | ||
# the job, if it exists | ||
config_args = config['args'] || config[:args] || {} | ||
config_args = config_args.merge(submitted_args) | ||
|
||
# Insert the args hash into config and queue the resque job | ||
config = config.merge('args' => config_args) | ||
Resque::Scheduler.enqueue_from_config(config) | ||
redirect_to ResqueWeb::Engine.app.url_helpers.overview_path | ||
end | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
...resque/scheduler/engine/app/helpers/resque_web/plugins/resque_scheduler/delayed_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ResqueWeb | ||
module Plugins | ||
module ResqueScheduler | ||
module DelayedHelper | ||
def format_time(t) | ||
t.strftime('%Y-%m-%d %H:%M:%S %z') | ||
end | ||
end | ||
end | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
...sque/scheduler/engine/app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module ResqueWeb | ||
module Plugins | ||
module ResqueScheduler | ||
module SchedulesHelper | ||
def scheduled_in_this_env?(name) | ||
return true if Resque.schedule[name]['rails_env'].nil? | ||
rails_env(name).split(/[\s,]+/).include?(Resque::Scheduler.env) | ||
end | ||
|
||
def rails_env(name) | ||
Resque.schedule[name]['rails_env'] | ||
end | ||
|
||
def schedule_interval_every(every) | ||
every = [*every] | ||
s = 'every: ' << every.first | ||
|
||
return s unless every.length > 1 | ||
|
||
s << ' (' | ||
meta = every.last.map do |key, value| | ||
"#{key.to_s.gsub(/_/, ' ')} #{value}" | ||
end | ||
s << meta.join(', ') << ')' | ||
end | ||
|
||
def schedule_interval(config) | ||
if config['every'] | ||
schedule_interval_every(config['every']) | ||
elsif config['cron'] | ||
'cron: ' + config['cron'].to_s | ||
else | ||
'Not currently scheduled' | ||
end | ||
end | ||
|
||
def schedule_class(config) | ||
if config['class'].nil? && !config['custom_job_class'].nil? | ||
config['custom_job_class'] | ||
else | ||
config['class'] | ||
end | ||
end | ||
|
||
def queue_from_class_name(class_name) | ||
Resque.queue_from_class( | ||
Resque::Scheduler::Util.constantize(class_name) | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
...que/scheduler/engine/app/views/resque_web/plugins/resque_scheduler/delayed/_next_more.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% # per_page was added in 1.23.1; gems which add to resque-server don't pass that variable along so it would crash %> | ||
<% # without a default value %> | ||
<% per_page ||= 20 %> | ||
<% if start - per_page >= 0 || start + per_page <= size %> | ||
<p class='pagination'> | ||
<% if start + per_page <= size %> | ||
<a href="<%= current_page %>?start=<%= start + per_page %>" class='more'>« | ||
Next</a> | ||
<% end %> | ||
|
||
<% (size / per_page.to_f - 1).ceil.downto(0).each do |page_num| %> | ||
<% if start == page_num * per_page %> | ||
<%= page_num %> | ||
<% else %> | ||
<a href="<%= current_page %>?start=<%= page_num * per_page %>"> <%= page_num %></a> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if start - per_page >= 0 %> | ||
<a href="<%= current_page %>?start=<%= start - per_page %>" class='less'>Previous »</a> | ||
<% end %> | ||
</p> | ||
<% end %> |
2 changes: 1 addition & 1 deletion
2
...ue/scheduler/server/views/search_form.erb → ...resque_scheduler/delayed/_search_form.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...que/scheduler/engine/app/views/resque_web/plugins/resque_scheduler/delayed/jobs_klass.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h1>Delayed jobs scheduled for <%= params[:klass] %> (<%= @args %>)</h1> | ||
|
||
<table class='jobs'> | ||
<tr> | ||
<th>Timestamp</th> | ||
</tr> | ||
|
||
<% @timestamps.each do |t| %> | ||
<tr> | ||
<td> | ||
<%= Time.at(t) %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
<% if @timestamps.empty? %> | ||
<tr> | ||
<td class='no-data'>There are no such jobs scheduled.</td> | ||
</tr> | ||
<% end %> | ||
</table> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How different is this from describing routes in a dedicated config/routes.rb file ?