diff --git a/lib/resque_scheduler/server.rb b/lib/resque_scheduler/server.rb index fcff12a2..d18d9acb 100644 --- a/lib/resque_scheduler/server.rb +++ b/lib/resque_scheduler/server.rb @@ -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 diff --git a/lib/resque_scheduler/server/views/scheduler.erb b/lib/resque_scheduler/server/views/scheduler.erb index a67aa1af..464d6791 100644 --- a/lib/resque_scheduler/server/views/scheduler.erb +++ b/lib/resque_scheduler/server/views/scheduler.erb @@ -16,7 +16,7 @@ Queue Arguments - <% 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] %> diff --git a/test/resque-web_test.rb b/test/resque-web_test.rb index 593dbe21..c958d353 100644 --- a/test/resque-web_test.rb +++ b/test/resque-web_test.rb @@ -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' => "* * * * *", @@ -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! @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 91a8867d..7fbf9484 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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