From 9ecf742360c6de6b6a42d412ccf2c24bc2bfaec1 Mon Sep 17 00:00:00 2001 From: Vernon Keenan Date: Tue, 19 Jan 2021 17:34:28 -0800 Subject: [PATCH] carefull... --- rules/new-lead.go | 36 +++++++++++++++++------------------- rules/root.go | 1 + 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/rules/new-lead.go b/rules/new-lead.go index 0b8de96..b7bea4b 100644 --- a/rules/new-lead.go +++ b/rules/new-lead.go @@ -4,6 +4,7 @@ import ( "time" "code.tnxs.net/taxnexus/lib/app" + "go.temporal.io/sdk/temporal" temporal_workflow "go.temporal.io/sdk/workflow" ) @@ -40,7 +41,7 @@ type NewLeadWorkflowWrapper struct { // NewLeadWorkflow is a Temporal workflow func NewLeadWorkflow(ctx temporal_workflow.Context, w NewLeadWorkflowWrapper) error { //nolint:gocritic // don't care - obj := app.LeadActivityWrapper{ + transferDetails := app.LeadActivityWrapper{ // Address: w.Address, Company: w.Company, Description: w.Description, @@ -62,27 +63,24 @@ func NewLeadWorkflow(ctx temporal_workflow.Context, w NewLeadWorkflowWrapper) er UTMTerm: w.UTMTerm, Website: w.Website, } - ctx = temporal_workflow. - WithActivityOptions( - ctx, - temporal_workflow.ActivityOptions{ - StartToCloseTimeout: time.Minute, - }) - err := temporal_workflow. - ExecuteActivity( - ctx, - StoreLeadActivity, - obj, - ).Get(ctx, nil) + 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) + err := temporal_workflow.ExecuteActivity(ctx, StoreLeadActivity, transferDetails).Get(ctx, nil) if err != nil { return err } - err = temporal_workflow. - ExecuteActivity( - ctx, - NotifyLeadActivity, - obj, - ).Get(ctx, nil) + err = temporal_workflow.ExecuteActivity(ctx, NotifyLeadActivity, transferDetails).Get(ctx, nil) if err != nil { return err } diff --git a/rules/root.go b/rules/root.go index 1e04440..b433c68 100644 --- a/rules/root.go +++ b/rules/root.go @@ -19,6 +19,7 @@ const getTimeout = 6 * time.Minute // const dateTimeFormat = "2006-01-02T15:04:05-0800" const postTimeout = 6 * time.Minute +const maxAttempts = 50 var sugar = logger.New(zapcore.InfoLevel)