lib/rules/new-lead.go

56 lines
1.7 KiB
Go
Raw Permalink Normal View History

2021-01-13 02:41:43 +00:00
package rules
import (
"time"
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-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: 📥")
sugar.Debugf("rules.NewLeadWorkflow: wrapper: %v", w)
2021-01-21 03:04:43 +00:00
transferDetails := NewLeadActivityWrapper(w)
2021-01-20 01:34:28 +00:00
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)
2021-01-20 01:44:51 +00:00
sugar.Debugf("rules.NewLeadWorkflow: ctx: %v", ctx)
sugar.Debugf("rules.NewLeadWorkflow: 📏 do Store", ctx)
2021-01-20 01:34:28 +00:00
err := temporal_workflow.ExecuteActivity(ctx, StoreLeadActivity, transferDetails).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-20 01:34:28 +00:00
err = temporal_workflow.ExecuteActivity(ctx, NotifyLeadActivity, transferDetails).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
}