lib/rules/new-user.go

47 lines
1.0 KiB
Go
Raw Normal View History

2021-01-18 03:13:54 +00:00
package rules
import (
"time"
"code.tnxs.net/taxnexus/lib/api/devops/devops_models"
"code.tnxs.net/taxnexus/lib/app"
"go.temporal.io/sdk/workflow"
)
2021-01-19 20:23:02 +00:00
// NewUserActivityWrapper wraps a contact, account, payment method and a user identifier (app.User)
type NewUserActivityWrapper struct {
2021-01-18 03:13:54 +00:00
User devops_models.User
Principal app.User
SagaID string
SagaType string
}
// NewUserWorkflow is a Temporal workflow
2021-01-19 20:23:02 +00:00
func NewUserWorkflow(ctx workflow.Context, payload *NewUserActivityWrapper) error {
2021-01-18 03:13:54 +00:00
ctx = workflow.WithActivityOptions(
ctx,
workflow.ActivityOptions{
StartToCloseTimeout: time.Minute,
})
err := workflow.ExecuteActivity(ctx,
StoreUserActivity,
2021-01-19 20:23:02 +00:00
&app.UserActivityWrapper{
2021-01-19 01:50:45 +00:00
Obj: payload.User,
APIKey: payload.Principal.APIKey,
SagaID: payload.SagaID,
SagaType: payload.SagaType,
2021-01-18 03:13:54 +00:00
}).Get(ctx, nil)
if err != nil {
return err
}
err = workflow.ExecuteActivity(
ctx,
NotifyLeadActivity,
payload,
).Get(ctx, nil)
if err != nil {
return err
}
return nil
}