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
35
35
end
36
36
37
37
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
39
47
end
40
48
41
49
def unschedule_recurring_tasks
Original file line number Diff line number Diff line change @@ -4,17 +4,21 @@ module SolidQueue
4
4
class Scheduler ::RecurringSchedule
5
5
include AppExecutor
6
6
7
- attr_reader :configured_tasks , :scheduled_tasks
7
+ attr_reader :configured_tasks , :invalid_tasks , : scheduled_tasks
8
8
9
9
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? )
11
11
@scheduled_tasks = Concurrent ::Hash . new
12
12
end
13
13
14
14
def empty?
15
15
configured_tasks . empty?
16
16
end
17
17
18
+ def valid?
19
+ invalid_tasks . empty?
20
+ end
21
+
18
22
def schedule_tasks
19
23
wrap_in_app_executor do
20
24
persist_tasks
Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ class SchedulerTest < ActiveSupport::TestCase
17
17
scheduler . stop
18
18
end
19
19
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
+
20
30
test "run more than one instance of the scheduler with recurring tasks" do
21
31
recurring_tasks = { example_task : { class : "AddToBufferJob" , schedule : "every second" , args : 42 } }
22
32
schedulers = 2 . times . collect do
You can’t perform that action at this time.
0 commit comments