Skip to content

Commit

Permalink
Do not call webhook when job does not change state
Browse files Browse the repository at this point in the history
  • Loading branch information
runabol committed Nov 8, 2023
1 parent 63c3bf9 commit 243497f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions middleware/job/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func Webhook(next HandlerFunc) HandlerFunc {
if err := next(ctx, et, j); err != nil {
return err
}
if et != StateChange {
return nil
}
if len(j.Webhooks) == 0 {
return nil
}
Expand Down
11 changes: 8 additions & 3 deletions middleware/job/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestWebhookOK(t *testing.T) {
}},
}

assert.NoError(t, hm(context.Background(), Read, j))
assert.NoError(t, hm(context.Background(), StateChange, j))
<-received
}

Expand Down Expand Up @@ -80,7 +80,7 @@ func TestWebhookRetry(t *testing.T) {
}},
}

assert.NoError(t, hm(context.Background(), Read, j))
assert.NoError(t, hm(context.Background(), StateChange, j))
<-received
}

Expand Down Expand Up @@ -118,6 +118,11 @@ func TestWebhookOKWithHeaders(t *testing.T) {
}},
}

assert.NoError(t, hm(context.Background(), Read, j))
assert.NoError(t, hm(context.Background(), StateChange, j))
<-received
}

func TestWebhookIgnored(t *testing.T) {
hm := ApplyMiddleware(NoOpHandlerFunc, []MiddlewareFunc{Webhook})
assert.NoError(t, hm(context.Background(), Read, nil))
}

0 comments on commit 243497f

Please sign in to comment.