lib/rules/new-lead.go

51 lines
1.0 KiB
Go
Raw 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"
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-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-14 06:36:35 +00:00
// NewLeadWorkflow is a Temporal workflow
func NewLeadWorkflow(ctx temporal_workflow.Context, payload *NewLeadWrapper) error {
ctx = temporal_workflow.
WithActivityOptions(
ctx,
temporal_workflow.ActivityOptions{
StartToCloseTimeout: time.Minute,
})
err := temporal_workflow.
ExecuteActivity(
ctx,
StoreLeadActivity,
&app.LeadChannelWrapper{
Obj: payload.Lead,
Principal: payload.Principal,
}).Get(ctx, nil)
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
2021-01-14 06:36:35 +00:00
err = temporal_workflow.
ExecuteActivity(
ctx,
NotifyLeadActivity,
&app.LeadChannelWrapper{
Obj: payload.Lead,
Principal: payload.Principal,
}).Get(ctx, nil)
2021-01-13 02:41:43 +00:00
if err != nil {
return err
}
return nil
}