Skip to content

Commit

Permalink
feat: persist webhook checks even if there's no schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 7, 2023
1 parent 0472e34 commit dadca0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fixtures/external/alertmanager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
"Expected-Fail": "true"
spec:
schedule: "@every 1m"
# schedule: "@every 1m" # (Not required for webhook checks)
webhook:
name: my-webhook
token:
Expand Down
10 changes: 6 additions & 4 deletions pkg/jobs/canary/canary_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ func (j CanaryJob) Run(ctx dutyjob.JobRuntime) error {
}
span.End()

if canaryCtx.Canary.Spec.Webhook != nil {
results = append(results, pkg.Success(canaryCtx.Canary.Spec.Webhook, canaryCtx.Canary))
}

// Get transformed checks before and after, and then delete the olds ones that are not in new set
existingTransformedChecks, _ := db.GetTransformedCheckIDs(ctx.Context, canaryID)
var transformedChecksCreated []string
Expand Down Expand Up @@ -317,6 +313,12 @@ func SyncCanaryJob(ctx context.Context, dbCanary pkg.Canary) error {
return err
}

if canary.Spec.Webhook != nil {
// Webhook checks can be persisted immediately as they do not require scheduling & running.
result := pkg.Success(canary.Spec.Webhook, *canary)
_ = cache.PostgresCache.Add(pkg.FromV1(*canary, canary.Spec.Webhook), pkg.CheckStatusFromResult(*result))
}

if canary.Spec.GetSchedule() == "@never" {
DeleteCanaryJob(canary.GetPersistedID())
return nil
Expand Down

0 comments on commit dadca0a

Please sign in to comment.