(ctx context.Context, nodeName string, templateScope string, tmpl *wfv1.Template, orgTmpl wfv1.TemplateReferenceHolder, opts *executeTemplateOpts)
| 3784 | } |
| 3785 | |
| 3786 | func (woc *wfOperationCtx) executeSuspend(ctx context.Context, nodeName string, templateScope string, tmpl *wfv1.Template, orgTmpl wfv1.TemplateReferenceHolder, opts *executeTemplateOpts) (*wfv1.NodeStatus, error) { |
| 3787 | node, err := woc.wf.GetNodeByName(nodeName) |
| 3788 | if err != nil { |
| 3789 | node = woc.initializeExecutableNode(ctx, nodeName, wfv1.NodeTypeSuspend, templateScope, tmpl, orgTmpl, opts.boundaryID, wfv1.NodePending, opts.nodeFlag, true) |
| 3790 | woc.resolveInputFieldsForSuspendNode(ctx, node) |
| 3791 | } |
| 3792 | woc.log.WithField("nodeName", nodeName).Info(ctx, "node suspended") |
| 3793 | |
| 3794 | // If there is either an active workflow deadline, or if this node is suspended with a duration, then the workflow |
| 3795 | // will need to be requeued after a certain amount of time |
| 3796 | var requeueTime *time.Time |
| 3797 | |
| 3798 | if tmpl.Suspend.Duration != "" { |
| 3799 | node, err := woc.wf.GetNodeByName(nodeName) |
| 3800 | if err != nil { |
| 3801 | return nil, err |
| 3802 | } |
| 3803 | suspendDuration, err := wfv1.ParseStringToDuration(tmpl.Suspend.Duration) |
| 3804 | if err != nil { |
| 3805 | return node, err |
| 3806 | } |
| 3807 | suspendDeadline := node.StartedAt.Add(suspendDuration) |
| 3808 | requeueTime = &suspendDeadline |
| 3809 | if time.Now().UTC().After(suspendDeadline) { |
| 3810 | // Suspension is expired, node can be resumed |
| 3811 | woc.log.WithField("nodeName", nodeName).Info(ctx, "auto resuming node") |
| 3812 | if err := wfutil.OverrideOutputParametersWithDefault(node.Outputs); err != nil { |
| 3813 | return node, err |
| 3814 | } |
| 3815 | _ = woc.markNodePhase(ctx, nodeName, wfv1.NodeSucceeded) |
| 3816 | return node, nil |
| 3817 | } |
| 3818 | } |
| 3819 | |
| 3820 | // workflowDeadline is the time when the workflow will be timed out, if any |
| 3821 | if workflowDeadline := woc.getWorkflowDeadline(); workflowDeadline != nil { |
| 3822 | // There is an active workflow deadline. If this node is suspended with a duration, choose the earlier time |
| 3823 | // between the two, otherwise choose the deadline time. |
| 3824 | if requeueTime == nil || workflowDeadline.Before(*requeueTime) { |
| 3825 | requeueTime = workflowDeadline |
| 3826 | } |
| 3827 | } |
| 3828 | |
| 3829 | if requeueTime != nil { |
| 3830 | woc.requeueAfter(time.Until(*requeueTime)) |
| 3831 | } |
| 3832 | |
| 3833 | _ = woc.markNodePhase(ctx, nodeName, wfv1.NodeRunning) |
| 3834 | return node, nil |
| 3835 | } |
| 3836 | |
| 3837 | func (woc *wfOperationCtx) resolveInputFieldsForSuspendNode(ctx context.Context, node *wfv1.NodeStatus) { |
| 3838 | if node.Inputs == nil { |
no test coverage detected