-
Notifications
You must be signed in to change notification settings - Fork 85
/
utils.go
69 lines (62 loc) · 2.23 KB
/
utils.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
64
65
66
67
68
69
package util
import (
"context"
"time"
ipfsClient "github.com/filecoin-project/bacalhau/pkg/ipfs"
"github.com/filecoin-project/bacalhau/pkg/model"
"github.com/filecoin-project/bacalhau/pkg/publisher"
"github.com/filecoin-project/bacalhau/pkg/publisher/combo"
"github.com/filecoin-project/bacalhau/pkg/publisher/estuary"
filecoinlotus "github.com/filecoin-project/bacalhau/pkg/publisher/filecoin_lotus"
"github.com/filecoin-project/bacalhau/pkg/publisher/ipfs"
"github.com/filecoin-project/bacalhau/pkg/publisher/noop"
"github.com/filecoin-project/bacalhau/pkg/publisher/tracing"
"github.com/filecoin-project/bacalhau/pkg/system"
)
func NewIPFSPublishers(
ctx context.Context,
cm *system.CleanupManager,
cl ipfsClient.Client,
estuaryAPIKey string,
lotusConfig *filecoinlotus.PublisherConfig,
) (publisher.PublisherProvider, error) {
defaultPriorityPublisherTimeout := time.Second * 2
noopPublisher := noop.NewNoopPublisher()
ipfsPublisher, err := ipfs.NewIPFSPublisher(ctx, cm, cl)
if err != nil {
return nil, err
}
// we don't want to enforce that every compute node needs to have an estuary API key
// and so let's only add the
var estuaryPublisher publisher.Publisher = ipfsPublisher
if estuaryAPIKey != "" {
estuaryPublisher = combo.NewPrioritizedFanoutPublisher(
defaultPriorityPublisherTimeout,
estuary.NewEstuaryPublisher(estuary.EstuaryPublisherConfig{APIKey: estuaryAPIKey}),
ipfsPublisher,
)
if err != nil {
return nil, err
}
}
var lotus publisher.Publisher = ipfsPublisher
if lotusConfig != nil {
lotus, err = filecoinlotus.NewPublisher(ctx, cm, *lotusConfig)
if err != nil {
return nil, err
}
}
return model.NewMappedProvider(map[model.Publisher]publisher.Publisher{
model.PublisherNoop: tracing.Wrap(noopPublisher),
model.PublisherIpfs: tracing.Wrap(ipfsPublisher),
model.PublisherEstuary: tracing.Wrap(estuaryPublisher),
model.PublisherFilecoin: combo.NewPiggybackedPublisher(tracing.Wrap(ipfsPublisher), tracing.Wrap(lotus)),
}), nil
}
func NewNoopPublishers(
_ context.Context,
_ *system.CleanupManager,
) (publisher.PublisherProvider, error) {
noopPublisher := noop.NewNoopPublisher()
return model.NewNoopProvider[model.Publisher, publisher.Publisher](noopPublisher), nil
}