lib/rules/new-lead.go

44 lines
957 B
Go
Raw Permalink Normal View History

2021-01-13 02:41:43 +00:00
package rules
import (
"time"
2021-01-13 05:09:16 +00:00
"code.tnxs.net/taxnexus/lib/api/crm/crm_models"
2021-01-13 02:41:43 +00:00
"code.tnxs.net/taxnexus/lib/app"
"go.temporal.io/sdk/workflow"
)
2021-01-13 05:09:16 +00:00
// NewLeadWrapper wraps a Lead and a user identifier (app.User)
type NewLeadWrapper struct {
Lead crm_models.Lead
Principal app.User
2021-01-13 05:30:35 +00:00
SagaID string
SagaType string
2021-01-13 05:09:16 +00:00
}
2021-01-13 02:41:43 +00:00
// NewLeadWorkflow is a workflow
2021-01-13 05:09:16 +00:00
func NewLeadWorkflow(ctx workflow.Context, payload *NewLeadWrapper) error {
2021-01-13 02:41:43 +00:00
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
StartToCloseTimeout: time.Minute,
})
err := workflow.ExecuteActivity(ctx,
StoreLeadActivity,
&app.LeadChannelWrapper{
2021-01-13 05:09:16 +00:00
Obj: payload.Lead,
2021-01-13 02:41:43 +00:00
Principal: payload.Principal,
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(ctx,
NotifyLeadActivity,
&app.LeadChannelWrapper{
2021-01-13 05:09:16 +00:00
Obj: payload.Lead,
2021-01-13 02:41:43 +00:00
Principal: payload.Principal,
}).Get(ctx, nil)
if err != nil {
return err
}
return nil
}