lib/rules/new-lead.go

56 lines
1.7 KiB
Go

package rules
import (
"time"
"go.temporal.io/sdk/temporal"
temporal_workflow "go.temporal.io/sdk/workflow"
)
// NewLeadWorkflowWrapper wraps a Lead with auth and saga info
type NewLeadWorkflowWrapper struct {
APIKey string
SagaID string
SagaType string
//
Company string
Description string
Email string
FirstName string
LastName string
UTMSource string
}
// NewLeadWorkflow is a Temporal workflow
func NewLeadWorkflow(ctx temporal_workflow.Context, w NewLeadWorkflowWrapper) error { //nolint:gocritic // don't care
sugar.Info("rules.NewLeadWorkflow: 📥")
sugar.Debugf("rules.NewLeadWorkflow: wrapper: %v", w)
transferDetails := NewLeadActivityWrapper(w)
retryPolicy := &temporal.RetryPolicy{
InitialInterval: time.Second,
MaximumInterval: time.Minute,
MaximumAttempts: maxAttempts,
}
options := temporal_workflow.ActivityOptions{
// Timeout options specify when to automatically timeout Actvitivy functions.
StartToCloseTimeout: time.Minute,
// Optionally provide a customized RetryPolicy.
// Temporal retries failures by default, this is just an example.
RetryPolicy: retryPolicy,
}
ctx = temporal_workflow.WithActivityOptions(ctx, options)
sugar.Debugf("rules.NewLeadWorkflow: ctx: %v", ctx)
sugar.Debugf("rules.NewLeadWorkflow: 📏 do Store", ctx)
err := temporal_workflow.ExecuteActivity(ctx, StoreLeadActivity, transferDetails).Get(ctx, nil)
if err != nil {
return err
}
sugar.Debugf("rules.NewLeadWorkflow: 📏 do Notify", ctx)
err = temporal_workflow.ExecuteActivity(ctx, NotifyLeadActivity, transferDetails).Get(ctx, nil)
if err != nil {
return err
}
sugar.Info("rules.NewLeadWorkflow: 👍 📤")
return nil
}