Skip to content
Open
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
44 changes: 22 additions & 22 deletions pkg/executor/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2335,25 +2335,25 @@ func makeRunner(step oamv1alpha1.WorkflowStep, subTaskRunners []types.TaskRunner
}
}
return v1alpha1.StepStatus{
Name: step.Name,
Type: "suspend",
ID: step.Name,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Reason: types.StatusReasonSuspend,
}, &types.Operation{
Suspend: true,
}, nil
Name: step.Name,
Type: "suspend",
ID: step.Name,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Reason: types.StatusReasonSuspend,
}, &types.Operation{
Suspend: true,
}, nil
}
case "terminate":
run = func(ctx wfContext.Context, options *types.TaskRunOptions) (v1alpha1.StepStatus, *types.Operation, error) {
return v1alpha1.StepStatus{
Name: step.Name,
Type: "terminate",
Phase: v1alpha1.WorkflowStepPhaseFailed,
Reason: types.StatusReasonTerminate,
}, &types.Operation{
Terminated: true,
}, nil
Name: step.Name,
Type: "terminate",
Phase: v1alpha1.WorkflowStepPhaseFailed,
Reason: types.StatusReasonTerminate,
}, &types.Operation{
Terminated: true,
}, nil
}
case "success":
run = func(ctx wfContext.Context, options *types.TaskRunOptions) (v1alpha1.StepStatus, *types.Operation, error) {
Expand All @@ -2378,13 +2378,13 @@ func makeRunner(step oamv1alpha1.WorkflowStep, subTaskRunners []types.TaskRunner
case "failed-after-retries":
run = func(ctx wfContext.Context, options *types.TaskRunOptions) (v1alpha1.StepStatus, *types.Operation, error) {
return v1alpha1.StepStatus{
Name: step.Name,
Type: "failed-after-retries",
Phase: v1alpha1.WorkflowStepPhaseFailed,
Reason: types.StatusReasonFailedAfterRetries,
}, &types.Operation{
FailedAfterRetries: true,
}, nil
Name: step.Name,
Type: "failed-after-retries",
Phase: v1alpha1.WorkflowStepPhaseFailed,
Reason: types.StatusReasonFailedAfterRetries,
}, &types.Operation{
FailedAfterRetries: true,
}, nil
}
case "error":
run = func(ctx wfContext.Context, options *types.TaskRunOptions) (v1alpha1.StepStatus, *types.Operation, error) {
Expand Down
31 changes: 23 additions & 8 deletions pkg/providers/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"gopkg.in/gomail.v2"

"github.com/kubevela/pkg/cache"
cuexruntime "github.com/kubevela/pkg/cue/cuex/runtime"

"github.com/kubevela/workflow/pkg/cue/model"
Expand Down Expand Up @@ -61,15 +62,28 @@ type MailVars struct {
// MailParams .
type MailParams = providertypes.Params[MailVars]

var emailRoutine sync.Map
var (
emailRoutine cache.Cache[string]
emailCacheOnce sync.Once
emailMu sync.Mutex
)

// InitEmailCache initializes the email cache for storing email sending routines.
func InitEmailCache(ctx context.Context) {
emailCacheOnce.Do(func() {
emailRoutine = cache.NewMemoryCacheStore[string](ctx)
})
}

// Send sends email
func Send(_ context.Context, params *MailParams) (res *any, err error) {
pCtx := params.ProcessContext
act := params.Action
id := fmt.Sprint(pCtx.GetData(model.ContextStepSessionID))
routine, ok := emailRoutine.Load(id)
emailMu.Lock()
routine, ok := emailRoutine.Get(id)
Comment thread
kash2104 marked this conversation as resolved.
Resolved
if ok {
emailMu.Unlock()
switch routine {
case "success":
emailRoutine.Delete(id)
Expand All @@ -82,7 +96,8 @@ func Send(_ context.Context, params *MailParams) (res *any, err error) {
return nil, fmt.Errorf("failed to send email: %v", routine)
}
} else {
emailRoutine.Store(id, "initializing")
emailRoutine.Put(id, "initializing", 0)
emailMu.Unlock()
}

sender := params.Params.From
Expand All @@ -95,13 +110,13 @@ func Send(_ context.Context, params *MailParams) (res *any, err error) {

dial := gomail.NewDialer(sender.Host, sender.Port, sender.Address, sender.Password)
go func() {
if routine, ok := emailRoutine.Load(id); ok && routine == "initializing" {
emailRoutine.Store(id, "sending")
if err = dial.DialAndSend(m); err != nil {
emailRoutine.Store(id, err.Error())
if routine, ok := emailRoutine.Get(id); ok && routine == "initializing" {
emailRoutine.Put(id, "sending", 0)
if err := dial.DialAndSend(m); err != nil {
emailRoutine.Put(id, err.Error(), 0)
return
}
emailRoutine.Store(id, "success")
emailRoutine.Put(id, "success", 0)
}
}()
act.Wait("wait for the email")
Expand Down
Loading
Loading