2021-01-13 02:41:43 +00:00
|
|
|
package rules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.tnxs.net/taxnexus/lib/app"
|
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-19 20:11:18 +00:00
|
|
|
// Address crm_models.Address
|
2021-01-19 17:45:58 +00:00
|
|
|
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
|
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-20 01:34:28 +00:00
|
|
|
transferDetails := app.LeadActivityWrapper{
|
2021-01-19 17:45:58 +00:00
|
|
|
// Address: w.Address,
|
2021-01-19 21:18:59 +00:00
|
|
|
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,
|
2021-01-19 17:45:58 +00:00
|
|
|
}
|
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
|
|
|
|
}
|