77 "fmt"
88
99 "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
10- "github.com/flyteorg/flytestdlib/config"
1110 "google.golang.org/grpc/credentials"
1211 "google.golang.org/grpc/credentials/insecure"
1312
@@ -19,8 +18,11 @@ import (
1918 "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery"
2019 "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core"
2120 "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core/template"
21+ "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/io"
2222 "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/ioutils"
2323 "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/webapi"
24+ "github.com/flyteorg/flytestdlib/config"
25+ "github.com/flyteorg/flytestdlib/logger"
2426 "github.com/flyteorg/flytestdlib/promutils"
2527 "google.golang.org/grpc"
2628)
@@ -176,17 +178,38 @@ func (p Plugin) Status(ctx context.Context, taskCtx webapi.StatusContext) (phase
176178 case admin .State_RETRYABLE_FAILURE :
177179 return core .PhaseInfoRetryableFailure (pluginErrors .TaskFailedWithError , "failed to run the job" , taskInfo ), nil
178180 case admin .State_SUCCEEDED :
179- if resource .Outputs != nil {
180- err := taskCtx .OutputWriter ().Put (ctx , ioutils .NewInMemoryOutputReader (resource .Outputs , nil , nil ))
181- if err != nil {
182- return core .PhaseInfoUndefined , err
183- }
181+ err = writeOutput (ctx , taskCtx , resource )
182+ if err != nil {
183+ logger .Errorf (ctx , "Failed to write output with err %s" , err .Error ())
184+ return core .PhaseInfoUndefined , err
184185 }
185186 return core .PhaseInfoSuccess (taskInfo ), nil
186187 }
187188 return core .PhaseInfoUndefined , pluginErrors .Errorf (core .SystemErrorCode , "unknown execution phase [%v]." , resource .State )
188189}
189190
191+ func writeOutput (ctx context.Context , taskCtx webapi.StatusContext , resource * ResourceWrapper ) error {
192+ taskTemplate , err := taskCtx .TaskReader ().Read (ctx )
193+ if err != nil {
194+ return err
195+ }
196+
197+ if taskTemplate .Interface == nil || taskTemplate .Interface .Outputs == nil || taskTemplate .Interface .Outputs .Variables == nil {
198+ logger .Debugf (ctx , "The task declares no outputs. Skipping writing the outputs." )
199+ return nil
200+ }
201+
202+ var opReader io.OutputReader
203+ if resource .Outputs != nil {
204+ logger .Debugf (ctx , "Agent returned an output" )
205+ opReader = ioutils .NewInMemoryOutputReader (resource .Outputs , nil , nil )
206+ } else {
207+ logger .Debugf (ctx , "Agent didn't return any output, assuming file based outputs." )
208+ opReader = ioutils .NewRemoteFileOutputReader (ctx , taskCtx .DataStore (), taskCtx .OutputWriter (), taskCtx .MaxDatasetSizeBytes ())
209+ }
210+ return taskCtx .OutputWriter ().Put (ctx , opReader )
211+ }
212+
190213func getFinalAgent (taskType string , cfg * Config ) (* Agent , error ) {
191214 if id , exists := cfg .AgentForTaskTypes [taskType ]; exists {
192215 if agent , exists := cfg .Agents [id ]; exists {
0 commit comments