From ed3214ce4355afe13d7d42229af369eb94a2a8b6 Mon Sep 17 00:00:00 2001 From: Vernon Keenan Date: Thu, 21 Jan 2021 09:28:52 -0800 Subject: [PATCH] debug --- ...new-developer.go => developer-workflow.go} | 0 rules/{new-lead.go => lead-workflow.go} | 43 ++++++++++++------- rules/lead.go | 9 ++-- rules/root.go | 16 ++++--- rules/{new-tenant.go => temant-workflow.go} | 0 ...w-tenantuser.go => tenantuser-workflow.go} | 0 rules/{new-user.go => user-workflow.go} | 0 7 files changed, 44 insertions(+), 24 deletions(-) rename rules/{new-developer.go => developer-workflow.go} (100%) rename rules/{new-lead.go => lead-workflow.go} (52%) rename rules/{new-tenant.go => temant-workflow.go} (100%) rename rules/{new-tenantuser.go => tenantuser-workflow.go} (100%) rename rules/{new-user.go => user-workflow.go} (100%) diff --git a/rules/new-developer.go b/rules/developer-workflow.go similarity index 100% rename from rules/new-developer.go rename to rules/developer-workflow.go diff --git a/rules/new-lead.go b/rules/lead-workflow.go similarity index 52% rename from rules/new-lead.go rename to rules/lead-workflow.go index c4e99d5..8f11858 100644 --- a/rules/new-lead.go +++ b/rules/lead-workflow.go @@ -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. - RetryPolicy: retryPolicy, + 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 } diff --git a/rules/lead.go b/rules/lead.go index df0c65b..bffd812 100644 --- a/rules/lead.go +++ b/rules/lead.go @@ -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 } diff --git a/rules/root.go b/rules/root.go index 795bdac..4f3295b 100644 --- a/rules/root.go +++ b/rules/root.go @@ -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" diff --git a/rules/new-tenant.go b/rules/temant-workflow.go similarity index 100% rename from rules/new-tenant.go rename to rules/temant-workflow.go diff --git a/rules/new-tenantuser.go b/rules/tenantuser-workflow.go similarity index 100% rename from rules/new-tenantuser.go rename to rules/tenantuser-workflow.go diff --git a/rules/new-user.go b/rules/user-workflow.go similarity index 100% rename from rules/new-user.go rename to rules/user-workflow.go