Skip to content

Commit

Permalink
Use schedule name as class name if unspecified
Browse files Browse the repository at this point in the history
resque-scheduler will use the name of the scheduler as the job class
name, if the name isn't specified in the 'class' attribute of the
schedule.  This was not being supported in Active Scheduler.  The
workaround is to simply specify the class name, but this change makes
Active Scheduler that much more of a drop-in.
  • Loading branch information
jeremycrosbie committed Oct 7, 2015
1 parent cb11543 commit e63b377
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_scheduler/resque_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.wrap(schedule)
class: 'ActiveScheduler::ResqueWrapper',
queue: queue,
args: [{
job_class: opts[:class],
job_class: opts[:class] || job,
queue_name: queue,
arguments: opts[:arguments]
}]
Expand Down
19 changes: 19 additions & 0 deletions spec/active_scheduler/resque_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@
expect(wrapped['no_queue_job']['queue']).to eq 'default'
end
end

context "when the schedule name is the class name" do
let(:schedule) { YAML.load_file 'spec/fixtures/schedule_name_is_class_name.yaml' }

it "queues up a job, using the schedule name for the class name" do
expect(wrapped['MyScheduleNameIsClassNameJob']).to eq(
"class" => "ActiveScheduler::ResqueWrapper",
"queue" => "myscheduledjobqueue",
"description" => "It's a self-named job.",
"cron" => "* * * * *",
"args" => [{
"job_class" => "MyScheduleNameIsClassNameJob",
"queue_name" => "myscheduledjobqueue",
"arguments" => nil
}]
)
end

end
end

describe ".perform" do
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/schedule_name_is_class_name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MyScheduleNameIsClassNameJob:
cron: "* * * * *"
queue: "myscheduledjobqueue"
args:
-
description: "It's a self-named job."

0 comments on commit e63b377

Please sign in to comment.