Skip to content

Commit f2f10f5

Browse files
committed
Store full recurring task configuration in process metadata
It'll be handy in Mission Control when we want to show the configured tasks because we need to aggregate them across dispatchers that might have different configurations.
1 parent d566c32 commit f2f10f5

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

lib/solid_queue/dispatcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def unload_recurring_schedule
5252
end
5353

5454
def metadata
55-
super.merge(batch_size: batch_size, concurrency_maintenance_interval: concurrency_maintenance&.interval, recurring_schedule: recurring_schedule.tasks.presence)
55+
super.merge(batch_size: batch_size, concurrency_maintenance_interval: concurrency_maintenance&.interval, recurring_schedule: recurring_schedule.tasks.presence )
5656
end
5757
end
5858
end

lib/solid_queue/dispatcher/recurring_schedule.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def unload_tasks
2727
end
2828

2929
def tasks
30-
configured_tasks.map(&:to_s)
30+
configured_tasks.each_with_object({}) { |task, hsh| hsh[task.key] = task.to_h }
3131
end
3232

3333
def inspect
34-
tasks.map(&:to_s).join(" | ")
34+
configured_tasks.map(&:to_s).join(" | ")
3535
end
3636

3737
private

lib/solid_queue/dispatcher/recurring_task.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def from_configuration(key, **options)
1717
def initialize(key, class_name:, schedule:, arguments: nil)
1818
@key = key
1919
@class_name = class_name
20-
@schedule = Fugit.parse(schedule)
20+
@schedule = schedule
2121
@arguments = Array(arguments)
2222
end
2323

@@ -26,7 +26,7 @@ def delay_from_now
2626
end
2727

2828
def next_time
29-
schedule.next_time.utc
29+
parsed_schedule.next_time.utc
3030
end
3131

3232
def enqueue(at:)
@@ -38,15 +38,19 @@ def enqueue(at:)
3838
end
3939

4040
def valid?
41-
schedule.instance_of?(Fugit::Cron)
41+
parsed_schedule.instance_of?(Fugit::Cron)
4242
end
4343

4444
def to_s
45-
"#{class_name}.perform_later(#{arguments.map(&:inspect).join(",")}) [ #{parsed_schedule} ]"
45+
"#{class_name}.perform_later(#{arguments.map(&:inspect).join(",")}) [ #{parsed_schedule.original.to_s} ]"
4646
end
4747

48-
def parsed_schedule
49-
schedule.original.to_s
48+
def to_h
49+
{
50+
schedule: schedule,
51+
class_name: class_name,
52+
arguments: arguments
53+
}
5054
end
5155

5256
private
@@ -70,6 +74,10 @@ def arguments_with_kwargs
7074
end
7175
end
7276

77+
def parsed_schedule
78+
@parsed_schedule ||= Fugit.parse(schedule)
79+
end
80+
7381
def job_class
7482
@job_class ||= class_name.safe_constantize
7583
end

test/unit/dispatcher_test.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class DispatcherTest < ActiveSupport::TestCase
3535
assert_equal "Dispatcher", process.kind
3636
assert_equal({ "polling_interval" => 0.1, "batch_size" => 10 }, process.metadata)
3737

38+
ensure
3839
no_concurrency_maintenance_dispatcher.stop
3940
end
4041

@@ -48,8 +49,11 @@ class DispatcherTest < ActiveSupport::TestCase
4849

4950
process = SolidQueue::Process.first
5051
assert_equal "Dispatcher", process.kind
51-
assert_equal [ "AddToBufferJob.perform_later(42) [ 0 * * * * ]" ], process.metadata["recurring_schedule"]
5252

53+
schedule_from_metadata = process.metadata["recurring_schedule"]
54+
assert_equal 1, schedule_from_metadata.size
55+
assert_equal({ "class_name" => "AddToBufferJob", "schedule" => "every hour", "arguments" => [ 42 ] }, schedule_from_metadata["example_task"])
56+
ensure
5357
with_recurring_schedule.stop
5458
end
5559

@@ -97,6 +101,7 @@ class DispatcherTest < ActiveSupport::TestCase
97101
assert_equal 0, SolidQueue::ScheduledExecution.count
98102
assert_equal 15, SolidQueue::ReadyExecution.count
99103

104+
ensure
100105
another_dispatcher.stop
101106
end
102107

0 commit comments

Comments
 (0)