youngoli commented on a change in pull request #16980:
URL: https://github.com/apache/beam/pull/16980#discussion_r821310770



##########
File path: sdks/go/pkg/beam/core/runtime/exec/plan.go
##########
@@ -131,6 +141,44 @@ func (p *Plan) Execute(ctx context.Context, id string, 
manager DataContext) erro
        return nil
 }
 
+// Runs any callbacks registered by the bundleFinalizer. Should be run on 
bundle finalization.

Review comment:
       Nit: Godoc comments should start with the name of the function. (See 
https://go.dev/blog/godoc)
   ```suggestion
   // Finalize runs any callbacks registered by the bundleFinalizer. Should be 
run on bundle finalization.
   ```

##########
File path: sdks/go/pkg/beam/core/runtime/exec/plan.go
##########
@@ -131,6 +141,44 @@ func (p *Plan) Execute(ctx context.Context, id string, 
manager DataContext) erro
        return nil
 }
 
+// Runs any callbacks registered by the bundleFinalizer. Should be run on 
bundle finalization.
+func (p *Plan) Finalize() error {
+       if p.status != Up {
+               return errors.Errorf("invalid status for plan %v: %v", p.id, 
p.status)
+       }
+       failedIndices := []int{}
+       for idx, bfc := range p.bf.callbacks {
+               if time.Now().Before(bfc.validUntil) {
+                       if err := bfc.callback(); err != nil {
+                               failedIndices = append(failedIndices, idx)
+                       }
+               }
+       }
+
+       newFinalizer := bundleFinalizer{
+               callbacks:         []bundleFinalizationCallback{},
+               lastValidCallback: time.Now(),
+       }
+
+       for _, idx := range failedIndices {
+               newFinalizer.callbacks = append(newFinalizer.callbacks, 
p.bf.callbacks[idx])
+               if 
newFinalizer.lastValidCallback.Before(p.bf.callbacks[idx].validUntil) {
+                       newFinalizer.lastValidCallback = 
p.bf.callbacks[idx].validUntil
+               }
+       }
+
+       p.bf = &newFinalizer
+
+       if len(failedIndices) > 0 {
+               return errors.Errorf("Plan %v failed %v callbacks", p.ID(), 
len(failedIndices))
+       }
+       return nil
+}
+
+func (p *Plan) GetExpirationTime() time.Time {

Review comment:
       Nit: This function should get a comment too.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to