/
singleton.go
46 lines (35 loc) · 1.08 KB
/
singleton.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package webhooks
import (
"context"
log "github.com/sirupsen/logrus"
"github.com/determined-ai/determined/master/pkg/model"
)
var defaultManager *WebhookManager
// SetDefault sets the default webhook manager singleton.
func SetDefault(w *WebhookManager) {
defaultManager = w
}
// ScanLogs sends webhooks for task logs. This should be called wherever we add task logs.
func ScanLogs(ctx context.Context, logs []*model.TaskLog) error {
if defaultManager == nil {
log.Error("webhook manager is uninitialized")
return nil
}
return defaultManager.scanLogs(ctx, logs)
}
// AddWebhook adds a Webhook and its Triggers to the DB.
func AddWebhook(ctx context.Context, w *Webhook) error {
if defaultManager == nil {
log.Error("webhook manager is uninitialized")
return nil
}
return defaultManager.addWebhook(ctx, w)
}
// DeleteWebhook deletes a Webhook and its Triggers from the DB.
func DeleteWebhook(ctx context.Context, id WebhookID) error {
if defaultManager == nil {
log.Error("webhook manager is uninitialized")
return nil
}
return defaultManager.deleteWebhook(ctx, id)
}