Skip to content

Commit ce154f4

Browse files
fix: guard periodic worker startup against supervisor failure
Only call ensure_started() for Oban workers after confirming the supervisor started successfully, preventing cascading errors when the endpoint or other children fail to start.
1 parent 1c4ce7f commit ce154f4

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

lib/sentinel_cp/application.ex

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,22 @@ defmodule SentinelCp.Application do
3131
opts = [strategy: :one_for_one, name: SentinelCp.Supervisor]
3232
result = Supervisor.start_link(children, opts)
3333

34-
# Start periodic workers
35-
SentinelCp.Rollouts.SchedulerWorker.ensure_started()
36-
SentinelCp.Nodes.DriftWorker.ensure_started()
37-
SentinelCp.Services.CertificateExpiryWorker.ensure_started()
38-
SentinelCp.Analytics.PruneWorker.ensure_started()
39-
SentinelCp.Services.DiscoverySyncWorker.ensure_started()
40-
SentinelCp.Services.CertificateRenewalWorker.ensure_started()
41-
SentinelCp.Analytics.WafEventPruneWorker.ensure_started()
42-
SentinelCp.Analytics.WafBaselineWorker.ensure_started()
43-
SentinelCp.Analytics.WafAnomalyWorker.ensure_started()
34+
# Start periodic workers (only if supervisor started successfully)
35+
case result do
36+
{:ok, _pid} ->
37+
SentinelCp.Rollouts.SchedulerWorker.ensure_started()
38+
SentinelCp.Nodes.DriftWorker.ensure_started()
39+
SentinelCp.Services.CertificateExpiryWorker.ensure_started()
40+
SentinelCp.Analytics.PruneWorker.ensure_started()
41+
SentinelCp.Services.DiscoverySyncWorker.ensure_started()
42+
SentinelCp.Services.CertificateRenewalWorker.ensure_started()
43+
SentinelCp.Analytics.WafEventPruneWorker.ensure_started()
44+
SentinelCp.Analytics.WafBaselineWorker.ensure_started()
45+
SentinelCp.Analytics.WafAnomalyWorker.ensure_started()
46+
47+
_ ->
48+
:ok
49+
end
4450

4551
result
4652
end

0 commit comments

Comments
 (0)