42 lines
921 B
Go
42 lines
921 B
Go
package rules
|
|
|
|
import (
|
|
"time"
|
|
|
|
"code.tnxs.net/taxnexus/lib/api/crm/crm_models"
|
|
"code.tnxs.net/taxnexus/lib/app"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
// NewLeadWrapper wraps a Lead and a user identifier (app.User)
|
|
type NewLeadWrapper struct {
|
|
Lead crm_models.Lead
|
|
Principal app.User
|
|
}
|
|
|
|
// NewLeadWorkflow is a workflow
|
|
func NewLeadWorkflow(ctx workflow.Context, payload *NewLeadWrapper) error {
|
|
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
|
|
StartToCloseTimeout: time.Minute,
|
|
})
|
|
err := workflow.ExecuteActivity(ctx,
|
|
StoreLeadActivity,
|
|
&app.LeadChannelWrapper{
|
|
Obj: payload.Lead,
|
|
Principal: payload.Principal,
|
|
}).Get(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = workflow.ExecuteActivity(ctx,
|
|
NotifyLeadActivity,
|
|
&app.LeadChannelWrapper{
|
|
Obj: payload.Lead,
|
|
Principal: payload.Principal,
|
|
}).Get(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|