Skip to content

Commit d3a8a56

Browse files
committed
Fix and simplify logging of recurring tasks enqueuing
Set level to debug for successful enqueue + skipping, and error for errors, instead of info for everything.
1 parent 32403b7 commit d3a8a56

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

lib/solid_queue/log_subscriber.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,12 @@ def enqueue_recurring_task(event)
4747
attributes = event.payload.slice(:task, :active_job_id, :enqueue_error)
4848
attributes[:at] = event.payload[:at]&.iso8601
4949

50-
if event.payload[:other_adapter]
51-
action = attributes[:active_job_id].present? ? "Enqueued recurring task outside Solid Queue" : "Error enqueuing recurring task"
52-
debug formatted_event(event, action: action, **attributes)
50+
if attributes[:active_job_id].nil? && event.payload[:skipped].nil?
51+
error formatted_event(event, action: "Error enqueuing recurring task", **attributes)
52+
elsif event.payload[:other_adapter]
53+
debug formatted_event(event, action: "Enqueued recurring task outside Solid Queue", **attributes)
5354
else
54-
action = case
55-
when event.payload[:skipped].present? then "Skipped recurring task – already dispatched"
56-
when attributes[:active_job_id].nil? then "Error enqueuing recurring task"
57-
else "Enqueued recurring task"
58-
end
59-
55+
action = event.payload[:skipped].present? ? "Skipped recurring task – already dispatched" : "Enqueued recurring task"
6056
debug formatted_event(event, action: action, **attributes)
6157
end
6258
end

test/unit/log_subscriber_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ def set_logger(logger)
3131
time = Time.now
3232
instrument "enqueue_recurring_task.solid_queue", task: :example_task, active_job_id: "b944ddbc-6a37-43c0-b661-4b56e57195f5", at: time
3333

34-
assert_match_logged :info, "Enqueued recurring task", "task: :example_task, active_job_id: \"b944ddbc-6a37-43c0-b661-4b56e57195f5\", at: \"#{time.iso8601}\""
34+
assert_match_logged :debug, "Enqueued recurring task", "task: :example_task, active_job_id: \"b944ddbc-6a37-43c0-b661-4b56e57195f5\", at: \"#{time.iso8601}\""
3535
end
3636

3737
test "recurring task skipped" do
3838
attach_log_subscriber
3939
time = Time.now
4040
instrument "enqueue_recurring_task.solid_queue", task: :example_task, skipped: true, at: time
4141

42-
assert_match_logged :info, "Skipped recurring task – already dispatched", "task: :example_task, at: \"#{time.iso8601}\""
42+
assert_match_logged :debug, "Skipped recurring task – already dispatched", "task: :example_task, at: \"#{time.iso8601}\""
4343
end
4444

4545
test "error enqueuing recurring task" do
4646
attach_log_subscriber
4747
time = Time.now
4848
instrument "enqueue_recurring_task.solid_queue", task: :example_task, enqueue_error: "Everything is broken", at: time
4949

50-
assert_match_logged :info, "Error enqueuing recurring task", "task: :example_task, enqueue_error: \"Everything is broken\", at: \"#{time.iso8601}\""
50+
assert_match_logged :error, "Error enqueuing recurring task", "task: :example_task, enqueue_error: \"Everything is broken\", at: \"#{time.iso8601}\""
5151
end
5252

5353
test "deregister process" do

0 commit comments

Comments
 (0)