Skip to content

Commit

Permalink
Merge pull request resque#367 from resque/86-show-jobs-for-current-en…
Browse files Browse the repository at this point in the history
…v-only

Only showing scheduled jobs that match current env or omit env
  • Loading branch information
Matteo Centenaro committed Feb 18, 2014
2 parents 2f82e04 + c568fbe commit 6613982
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/resque_scheduler/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def schedule_class(config)
config['class']
end
end

def scheduled_in_this_env?(name)
return true if Resque.schedule[name]['rails_env'].nil?
Resque.schedule[name]['rails_env'] == Resque::Scheduler.env
end
end

get "/schedule" do
Expand Down
2 changes: 1 addition & 1 deletion lib/resque_scheduler/server/views/scheduler.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<th>Queue</th>
<th>Arguments</th>
</tr>
<% Resque.schedule.keys.sort.each do |name| %>
<% Resque.schedule.keys.sort.select { |n| scheduled_in_this_env?(n) }.each do |name| %>
<% config = Resque.schedule[name] %>
<tr>
<td style="padding-top: 12px; padding-bottom: 2px; width: 10px">
Expand Down
13 changes: 12 additions & 1 deletion test/resque-web_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

context "on GET to /schedule with scheduled jobs" do
setup do
ENV['rails_env'] = 'production'
Resque::Scheduler.env = 'production'
Resque.schedule = {
'some_ivar_job' => {
'cron' => "* * * * *",
Expand All @@ -26,6 +26,13 @@
'args' => {
'b' => 'blah'
}
},
'some_fancy_job' => {
'every' => ['1m'],
'queue' => 'fancy',
'class' => 'SomeFancyJob',
'args' => 'sparkles',
'rails_env' => 'fancy'
}
}
Resque::Scheduler.load_schedule!
Expand All @@ -37,6 +44,10 @@
test 'see the scheduled job' do
assert last_response.body.include?('SomeIvarJob')
end

test 'excludes jobs for other envs' do
assert !last_response.body.include?('SomeFancyJob')
end
end

context "on GET to /delayed" do
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class SomeIvarJob < SomeJob
@queue = :ivar
end

class SomeFancyJob < SomeJob
def self.queue
:fancy
end
end

class SomeQuickJob < SomeJob
@queue = :quick
end
Expand Down

0 comments on commit 6613982

Please sign in to comment.