-
Notifications
You must be signed in to change notification settings - Fork 85
/
publisher.go
63 lines (50 loc) · 1.76 KB
/
publisher.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package noop
import (
"context"
"github.com/bacalhau-project/bacalhau/pkg/models"
"github.com/bacalhau-project/bacalhau/pkg/publisher"
)
type PublisherHandlerIsInstalled func(ctx context.Context) (bool, error)
type PublisherHandlerPublishResult func(
ctx context.Context, execution *models.Execution, resultPath string) (models.SpecConfig, error)
func ErrorResultPublisher(err error) PublisherHandlerPublishResult {
return func(ctx context.Context, execution *models.Execution, resultPath string) (models.SpecConfig, error) {
return models.SpecConfig{}, err
}
}
type PublisherExternalHooks struct {
IsInstalled PublisherHandlerIsInstalled
PublishResult PublisherHandlerPublishResult
}
type PublisherConfig struct {
ExternalHooks PublisherExternalHooks
}
type NoopPublisher struct {
externalHooks PublisherExternalHooks
}
func NewNoopPublisher() *NoopPublisher {
return &NoopPublisher{}
}
func NewNoopPublisherWithConfig(config PublisherConfig) *NoopPublisher {
p := NewNoopPublisher()
p.externalHooks = config.ExternalHooks
return p
}
func (publisher *NoopPublisher) IsInstalled(ctx context.Context) (bool, error) {
if publisher.externalHooks.IsInstalled != nil {
return publisher.externalHooks.IsInstalled(ctx)
}
return true, nil
}
func (publisher *NoopPublisher) ValidateJob(ctx context.Context, j models.Job) error {
return nil
}
func (publisher *NoopPublisher) PublishResult(
ctx context.Context, execution *models.Execution, resultPath string) (models.SpecConfig, error) {
if publisher.externalHooks.PublishResult != nil {
return publisher.externalHooks.PublishResult(ctx, execution, resultPath)
}
return models.SpecConfig{}, nil
}
// Compile-time check that Publisher implements the correct interface:
var _ publisher.Publisher = (*NoopPublisher)(nil)