lib/rules/new-lead.go

95 lines
2.7 KiB
Go

package rules
import (
"time"
"code.tnxs.net/taxnexus/lib/app"
"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
//
// Address crm_models.Address
Company string
Description string
Email string
FirstName string
LastName string
MobilePhone string
Name string
OwnerID string
PartnerAccountID string
Phone string
ProductID string
RefererURL string
Status string
TenantID string
Title string
Type string
UTMCampaign string
UTMContent string
UTMMedium string
UTMSource string
UTMTerm string
Website 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 := app.LeadActivityWrapper{
// Address: w.Address,
Company: w.Company,
Description: w.Description,
Email: w.Email,
FirstName: w.FirstName,
LastName: w.LastName,
MobilePhone: w.MobilePhone,
Name: w.Name,
Phone: w.Phone,
RefererURL: w.RefererURL,
Status: w.Status,
TenantID: w.TenantID,
Title: w.Title,
Type: w.Type,
UTMCampaign: w.UTMCampaign,
UTMContent: w.UTMContent,
UTMMedium: w.UTMMedium,
UTMSource: w.UTMSource,
UTMTerm: w.UTMTerm,
Website: w.Website,
}
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
}