This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
future_file_reader.go
76 lines (63 loc) · 2.55 KB
/
future_file_reader.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
70
71
72
73
74
75
76
package task
import (
"context"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core"
"github.com/lyft/flytestdlib/logger"
"github.com/lyft/flytestdlib/storage"
"github.com/pkg/errors"
"github.com/lyft/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
)
// TODO this file exists only until we need to support dynamic nodes instead of closure.
// Once closure migration is done, this file should be deleted.
const implicitFutureFileName = "futures.pb"
const implicitCompileWorkflowsName = "futures_compiled.pb"
type FutureFileReader struct {
RemoteFileWorkflowStore
loc storage.DataReference
cacheLoc storage.DataReference
store *storage.DataStore
}
func (f FutureFileReader) Exists(ctx context.Context) (bool, error) {
metadata, err := f.store.Head(ctx, f.loc)
// If no futures file produced, then declare success and return.
if err != nil {
logger.Warnf(ctx, "Failed to read futures file. Error: %v", err)
return false, errors.Wrap(err, "Failed to do HEAD on futures file.")
}
return metadata.Exists(), nil
}
func (f FutureFileReader) Read(ctx context.Context) (*core.DynamicJobSpec, error) {
djSpec := &core.DynamicJobSpec{}
if err := f.store.ReadProtobuf(ctx, f.loc, djSpec); err != nil {
logger.Warnf(ctx, "Failed to read futures file. Error: %v", err)
return nil, errors.Wrap(err, "Failed to read futures protobuf file.")
}
return djSpec, nil
}
func (f FutureFileReader) CacheExists(ctx context.Context) (bool, error) {
return f.RemoteFileWorkflowStore.Exists(ctx, f.cacheLoc)
}
func (f FutureFileReader) Cache(ctx context.Context, wf *v1alpha1.FlyteWorkflow) error {
return f.RemoteFileWorkflowStore.Put(ctx, wf, f.cacheLoc)
}
func (f FutureFileReader) RetrieveCache(ctx context.Context) (*v1alpha1.FlyteWorkflow, error) {
return f.RemoteFileWorkflowStore.Get(ctx, f.cacheLoc)
}
func NewRemoteFutureFileReader(ctx context.Context, dataDir storage.DataReference, store *storage.DataStore) (FutureFileReader, error) {
loc, err := store.ConstructReference(ctx, dataDir, implicitFutureFileName)
if err != nil {
logger.Warnf(ctx, "Failed to construct data path for futures file. Error: %v", err)
return FutureFileReader{}, err
}
cacheLoc, err := store.ConstructReference(ctx, dataDir, implicitCompileWorkflowsName)
if err != nil {
logger.Warnf(ctx, "Failed to construct data path for compile workflows file, error: %s", err)
return FutureFileReader{}, err
}
return FutureFileReader{
loc: loc,
cacheLoc: cacheLoc,
store: store,
RemoteFileWorkflowStore: NewRemoteWorkflowStore(store),
}, nil
}