File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,15 @@ def run
3535 end
3636
3737 def schedule_recurring_tasks
38- recurring_schedule . schedule_tasks
38+ if recurring_schedule . valid?
39+ recurring_schedule . schedule_tasks
40+ else
41+ error_messages = recurring_schedule . invalid_tasks . map do |task |
42+ "#{ task . key } : #{ task . errors . full_messages . to_sentence } "
43+ end . join ( ", " )
44+
45+ raise "Invalid recurring tasks: #{ error_messages } "
46+ end
3947 end
4048
4149 def unschedule_recurring_tasks
Original file line number Diff line number Diff line change @@ -4,17 +4,21 @@ module SolidQueue
44 class Scheduler ::RecurringSchedule
55 include AppExecutor
66
7- attr_reader :configured_tasks , :scheduled_tasks
7+ attr_reader :configured_tasks , :invalid_tasks , : scheduled_tasks
88
99 def initialize ( tasks )
10- @configured_tasks = Array ( tasks ) . map { |task | SolidQueue ::RecurringTask . wrap ( task ) } . select ( &:valid? )
10+ @configured_tasks , @invalid_tasks = Array ( tasks ) . map { |task | SolidQueue ::RecurringTask . wrap ( task ) } . partition ( &:valid? )
1111 @scheduled_tasks = Concurrent ::Hash . new
1212 end
1313
1414 def empty?
1515 configured_tasks . empty?
1616 end
1717
18+ def valid?
19+ invalid_tasks . empty?
20+ end
21+
1822 def schedule_tasks
1923 wrap_in_app_executor do
2024 persist_tasks
Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ class SchedulerTest < ActiveSupport::TestCase
1717 scheduler . stop
1818 end
1919
20+ test "recurring schedule has an invalid task" do
21+ invalid_recurring_tasks = { example_task : { class : "BarBarBarBarJob" , schedule : "every hour" , args : 42 } }
22+
23+ error = assert_raises ( RuntimeError ) do
24+ SolidQueue ::Scheduler . new ( recurring_tasks : invalid_recurring_tasks ) . tap ( &:start )
25+ end
26+
27+ assert_equal "Invalid recurring tasks: example_task: Class name doesn't correspond to an existing class" , error . message
28+ end
29+
2030 test "run more than one instance of the scheduler with recurring tasks" do
2131 recurring_tasks = { example_task : { class : "AddToBufferJob" , schedule : "every second" , args : 42 } }
2232 schedulers = 2 . times . collect do
You can’t perform that action at this time.
0 commit comments