github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/publisher/ipfs/publisher.go (about)

     1  package ipfs
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/filecoin-project/bacalhau/pkg/ipfs"
     7  	"github.com/filecoin-project/bacalhau/pkg/job"
     8  	"github.com/filecoin-project/bacalhau/pkg/model"
     9  	"github.com/filecoin-project/bacalhau/pkg/publisher"
    10  	"github.com/filecoin-project/bacalhau/pkg/system"
    11  	"github.com/rs/zerolog/log"
    12  )
    13  
    14  type IPFSPublisher struct {
    15  	IPFSClient ipfs.Client
    16  }
    17  
    18  func NewIPFSPublisher(
    19  	ctx context.Context,
    20  	_ *system.CleanupManager,
    21  	cl ipfs.Client,
    22  ) (*IPFSPublisher, error) {
    23  	log.Ctx(ctx).Debug().Msgf("IPFS publisher initialized for node: %s", cl.APIAddress())
    24  	return &IPFSPublisher{
    25  		IPFSClient: cl,
    26  	}, nil
    27  }
    28  
    29  func (publisher *IPFSPublisher) IsInstalled(ctx context.Context) (bool, error) {
    30  	_, err := publisher.IPFSClient.ID(ctx)
    31  	return err == nil, err
    32  }
    33  
    34  func (publisher *IPFSPublisher) PublishShardResult(
    35  	ctx context.Context,
    36  	shard model.JobShard,
    37  	hostID string,
    38  	shardResultPath string,
    39  ) (model.StorageSpec, error) {
    40  	cid, err := publisher.IPFSClient.Put(ctx, shardResultPath)
    41  	if err != nil {
    42  		return model.StorageSpec{}, err
    43  	}
    44  	return job.GetPublishedStorageSpec(shard, model.StorageSourceIPFS, hostID, cid), nil
    45  }
    46  
    47  // Compile-time check that Verifier implements the correct interface:
    48  var _ publisher.Publisher = (*IPFSPublisher)(nil)