-
Notifications
You must be signed in to change notification settings - Fork 539
/
writer_processor.go
62 lines (52 loc) · 1.83 KB
/
writer_processor.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
package catalog
import (
"context"
"fmt"
"reflect"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flyte/flyteplugins/go/tasks/errors"
"github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/io"
"github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/workqueue"
"github.com/flyteorg/flyte/flytestdlib/logger"
)
type WriterWorkItem struct {
// WriterWorkItem Inputs
key Key
data io.OutputReader
metadata Metadata
}
func NewWriterWorkItem(key Key, data io.OutputReader, metadata Metadata) *WriterWorkItem {
return &WriterWorkItem{
key: key,
data: data,
metadata: metadata,
}
}
type writerProcessor struct {
catalogClient Client
}
func (p writerProcessor) Process(ctx context.Context, workItem workqueue.WorkItem) (workqueue.WorkStatus, error) {
wi, casted := workItem.(*WriterWorkItem)
if !casted {
return workqueue.WorkStatusNotDone, fmt.Errorf("wrong work item type. Received: %v", reflect.TypeOf(workItem))
}
status, err := p.catalogClient.Put(ctx, wi.key, wi.data, wi.metadata)
if err != nil {
logger.Errorf(ctx, "Error putting to catalog [%s]", err)
return workqueue.WorkStatusNotDone, errors.Wrapf(errors.DownstreamSystemError, err,
"Error writing to catalog, key id [%v] cache version [%v]",
wi.key.Identifier, wi.key.CacheVersion)
}
if status.GetCacheStatus() == core.CatalogCacheStatus_CACHE_PUT_FAILURE {
return workqueue.WorkStatusNotDone, errors.Errorf(errors.DownstreamSystemError,
"Error writing to catalog, key id [%v] cache version [%v]",
wi.key.Identifier, wi.key.CacheVersion)
}
logger.Debugf(ctx, "Successfully wrote to catalog. Key [%v]", wi.key)
return workqueue.WorkStatusSucceeded, nil
}
func NewWriterProcessor(catalogClient Client) workqueue.Processor {
return writerProcessor{
catalogClient: catalogClient,
}
}