parent
a12863e619
commit
ed3214ce43
|
@ -1,12 +1,13 @@
|
|||
package rules
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.temporal.io/sdk/temporal"
|
||||
temporal_workflow "go.temporal.io/sdk/workflow"
|
||||
)
|
||||
|
||||
// NewLeadWorkflowID is the text identifier for new-lead-workflow
|
||||
const NewLeadWorkflowID = "new-lead-workflow"
|
||||
|
||||
// NewLeadWorkflowWrapper wraps a Lead with auth and saga info
|
||||
type NewLeadWorkflowWrapper struct {
|
||||
APIKey string
|
||||
|
@ -24,29 +25,41 @@ type NewLeadWorkflowWrapper struct {
|
|||
// 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)
|
||||
sugar.Debugf("rules.NewLeadWorkflow: ctx: %v", ctx)
|
||||
sugar.Debugf("rules.NewLeadWorkflow: w: %v", w)
|
||||
activityDetails := NewLeadActivityWrapper(w)
|
||||
retryPolicy := &temporal.RetryPolicy{
|
||||
InitialInterval: time.Second,
|
||||
MaximumInterval: time.Minute,
|
||||
MaximumAttempts: maxAttempts,
|
||||
InitialInterval: initialInterval,
|
||||
BackoffCoefficient: backoffCoefficient,
|
||||
MaximumInterval: maximumInterval,
|
||||
MaximumAttempts: maximumAttempts,
|
||||
}
|
||||
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.
|
||||
TaskQueue: TaxnexusRulesTaskQueueID,
|
||||
ScheduleToCloseTimeout: scheduleToCloseTimeout,
|
||||
ScheduleToStartTimeout: scheduleToStartTimeout,
|
||||
StartToCloseTimeout: startToCloseTimeout,
|
||||
HeartbeatTimeout: heartbeatTimeout,
|
||||
WaitForCancellation: waitForCancelation,
|
||||
ActivityID: NewLeadWorkflowID,
|
||||
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)
|
||||
err := temporal_workflow.ExecuteActivity(
|
||||
ctx,
|
||||
StoreLeadActivity,
|
||||
activityDetails,
|
||||
).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)
|
||||
err = temporal_workflow.ExecuteActivity(
|
||||
ctx,
|
||||
NotifyLeadActivity,
|
||||
activityDetails,
|
||||
).Get(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
|
@ -29,6 +29,8 @@ type NewLeadActivityWrapper struct {
|
|||
|
||||
// StoreLeadActivity posts a new lead object to datastore
|
||||
func StoreLeadActivity(ctx workflow.Context, w NewLeadActivityWrapper) error { //nolint:gocritic // don't care
|
||||
sugar.Info("rules.StoreLeadActivity: 📥")
|
||||
sugar.Debugf("rules.StoreLeadActivity: 📏 ctx: %v", ctx)
|
||||
obj := &crm_models.Lead{
|
||||
Company: w.Company,
|
||||
Description: w.Description,
|
||||
|
@ -51,13 +53,14 @@ func StoreLeadActivity(ctx workflow.Context, w NewLeadActivityWrapper) error { /
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sugar.Info("crm.storeLead: 👍 📤")
|
||||
sugar.Info("rules.StoreLeadActivity: 👍 📤")
|
||||
return nil
|
||||
}
|
||||
|
||||
// NotifyLeadActivity sends an email to a new lead
|
||||
func NotifyLeadActivity(ctx context.Context, w NewLeadActivityWrapper) error { //nolint:gocritic,lll // todo #2 need email templates
|
||||
sugar.Info("workflow.notifyLead: 📥")
|
||||
sugar.Info("rules.NotifyLeadActivity: 📥")
|
||||
sugar.Debugf("rules.StoreLeadActivity: 📏 ctx: %v", ctx)
|
||||
var buf bytes.Buffer
|
||||
const textBody = `
|
||||
|
||||
|
@ -98,6 +101,6 @@ Alert! New Lead Inquiry from Taxnexus.io website.
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sugar.Info("workflow.notifyLead: 👍 📤")
|
||||
sugar.Info("rules.NotifyLeadActivity: 👍 📤")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -15,11 +15,18 @@ import (
|
|||
)
|
||||
|
||||
// const dateFormat = "2006-01-02"
|
||||
const getTimeout = 6 * time.Minute
|
||||
|
||||
// const dateTimeFormat = "2006-01-02T15:04:05-0800"
|
||||
const backoffCoefficient = 2.0
|
||||
const getTimeout = 6 * time.Minute
|
||||
const heartbeatTimeout = 0
|
||||
const initialInterval = time.Second
|
||||
const maximumAttempts = 50
|
||||
const maximumInterval = time.Minute
|
||||
const postTimeout = 6 * time.Minute
|
||||
const maxAttempts = 50
|
||||
const scheduleToCloseTimeout = 0
|
||||
const scheduleToStartTimeout = 0
|
||||
const startToCloseTimeout = time.Minute
|
||||
const waitForCancelation = false
|
||||
|
||||
var sugar = logger.New(zapcore.DebugLevel)
|
||||
|
||||
|
@ -28,9 +35,6 @@ var devopsClient = devops_client.Default
|
|||
var opsClient = ops_client.Default
|
||||
var workflowClient = workflow_client.Default
|
||||
|
||||
// NewLeadWorkflowID is the text identifier for new-lead-workflow
|
||||
const NewLeadWorkflowID = "new-lead-workflow"
|
||||
|
||||
// NewDeveloperWorkflowID is the text identifier for new-developer-workflow
|
||||
const NewDeveloperWorkflowID = "new-developer-workflow"
|
||||
|
||||
|
|
Loading…
Reference in New Issue