Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix auto resume in suspend #140

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/providers/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (h *provider) Fail(ctx monitorContext.Context, wfCtx wfContext.Context, v *
func (h *provider) Suspend(ctx monitorContext.Context, wfCtx wfContext.Context, v *value.Value, act types.Action) error {
stepID := fmt.Sprint(h.pCtx.GetData(model.ContextStepSessionID))
timestamp := wfCtx.GetMutableValue(stepID, ResumeTimeStamp)
var msg string
if v != nil {
msg, _ = v.GetString("message")
}
if timestamp != "" {
t, err := time.Parse(time.RFC3339, timestamp)
if err != nil {
Expand All @@ -136,9 +140,9 @@ func (h *provider) Suspend(ctx monitorContext.Context, wfCtx wfContext.Context,
act.Resume("")
return nil
}
act.Suspend(msg)
return nil
}
var msg string
if v != nil {
d, _ := v.LookupValue("duration")
if d != nil && d.CueValue().Exists() {
Expand All @@ -152,15 +156,15 @@ func (h *provider) Suspend(ctx monitorContext.Context, wfCtx wfContext.Context,
}
wfCtx.SetMutableValue(time.Now().Add(duration).Format(time.RFC3339), stepID, ResumeTimeStamp)
}
msg, _ = v.GetString("message")
}
if ts := wfCtx.GetMutableValue(stepID, v.FieldName(), SuspendTimeStamp); ts != "" {
if act.GetStatus().Phase == v1alpha1.WorkflowStepPhaseRunning {
// if it is already suspended before and has been resumed, we should not suspend it again.
return nil
}
} else {
wfCtx.SetMutableValue(time.Now().Format(time.RFC3339), stepID, v.FieldName(), SuspendTimeStamp)
}
wfCtx.SetMutableValue(time.Now().Format(time.RFC3339), stepID, v.FieldName(), SuspendTimeStamp)
act.Suspend(msg)
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/providers/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ message: "hello suspend"
r.NoError(err)
r.Equal(act.suspend, true)
r.Equal(act.msg, "hello suspend")
// test second time to check if the suspend is resumed in 1s
err = p.Suspend(nil, wfCtx, v, act)
r.NoError(err)
r.Equal(act.suspend, true)
time.Sleep(time.Second)
err = p.Suspend(nil, wfCtx, v, act)
r.NoError(err)
Expand Down
2 changes: 0 additions & 2 deletions pkg/stdlib/actions/v1/op.cue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
duration?: string
// +usage=Optional message that will be shown in workflow step status, note that the message might be override by other actions.
message?: string
// +usage=The time when the step is suspended, it will be set when the action is executed.
suspendedAt?: string
}

#Break: {
Expand Down