lib/rules/lead-workflow.go

69 lines
1.9 KiB
Go
Raw Permalink Normal View History

2021-01-13 02:41:43 +00:00
package rules
import (
2021-01-20 01:34:28 +00:00
"go.temporal.io/sdk/temporal"
2021-01-14 06:36:35 +00:00
temporal_workflow "go.temporal.io/sdk/workflow"
2021-01-13 02:41:43 +00:00
)
2021-01-21 17:28:52 +00:00
// NewLeadWorkflowID is the text identifier for new-lead-workflow
const NewLeadWorkflowID = "new-lead-workflow"
2021-01-19 20:11:18 +00:00
// NewLeadWorkflowWrapper wraps a Lead with auth and saga info
type NewLeadWorkflowWrapper struct {
2021-01-20 01:17:06 +00:00
APIKey string
SagaID string
SagaType string
//
2021-01-21 03:04:43 +00:00
Company string
Description string
Email string
FirstName string
LastName string
UTMSource string
2021-01-13 05:09:16 +00:00
}
2021-01-14 06:36:35 +00:00
// NewLeadWorkflow is a Temporal workflow
2021-01-19 20:11:18 +00:00
func NewLeadWorkflow(ctx temporal_workflow.Context, w NewLeadWorkflowWrapper) error { //nolint:gocritic // don't care
2021-01-20 01:44:51 +00:00
sugar.Info("rules.NewLeadWorkflow: 📥")
2021-01-21 17:28:52 +00:00
sugar.Debugf("rules.NewLeadWorkflow: ctx: %v", ctx)
sugar.Debugf("rules.NewLeadWorkflow: w: %v", w)
activityDetails := NewLeadActivityWrapper(w)
2021-01-20 01:34:28 +00:00
retryPolicy := &temporal.RetryPolicy{
2021-01-21 17:28:52 +00:00
InitialInterval: initialInterval,
BackoffCoefficient: backoffCoefficient,
MaximumInterval: maximumInterval,
MaximumAttempts: maximumAttempts,
2021-01-20 01:34:28 +00:00
}
options := temporal_workflow.ActivityOptions{
2021-01-21 17:28:52 +00:00
TaskQueue: TaxnexusRulesTaskQueueID,
ScheduleToCloseTimeout: scheduleToCloseTimeout,
ScheduleToStartTimeout: scheduleToStartTimeout,
StartToCloseTimeout: startToCloseTimeout,
HeartbeatTimeout: heartbeatTimeout,
WaitForCancellation: waitForCancelation,
ActivityID: NewLeadWorkflowID,
RetryPolicy: retryPolicy,
2021-01-20 01:34:28 +00:00
}
ctx = temporal_workflow.WithActivityOptions(ctx, options)
2021-01-20 01:44:51 +00:00
sugar.Debugf("rules.NewLeadWorkflow: 📏 do Store", ctx)
2021-01-21 17:28:52 +00:00
err := temporal_workflow.ExecuteActivity(
ctx,
StoreLeadActivity,
activityDetails,
).Get(ctx, nil)
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
2021-01-20 01:44:51 +00:00
sugar.Debugf("rules.NewLeadWorkflow: 📏 do Notify", ctx)
2021-01-21 17:28:52 +00:00
err = temporal_workflow.ExecuteActivity(
ctx,
NotifyLeadActivity,
activityDetails,
).Get(ctx, nil)
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
2021-01-20 01:44:51 +00:00
sugar.Info("rules.NewLeadWorkflow: 👍 📤")
2021-01-13 02:41:43 +00:00
return nil
}