-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sign_up.go
49 lines (42 loc) · 1.26 KB
/
Sign_up.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package command
import (
"context"
"fmt"
"github.com/sajjad1993/todo/internal/common/broker_utils"
"github.com/sajjad1993/todo/internal/common/command_utils"
"github.com/sajjad1993/todo/internal/gateway/app/publisher"
)
type SignUp struct {
Name string
DoneName string
publisher publisher.CommandPublisher
*ChannelCommandManager
}
func (c *SignUp) GetName() string {
return c.Name
}
func (c *SignUp) GetDoneName() string {
return c.DoneName
}
func (c *SignUp) Execute(ctx context.Context, message *command_utils.CommandMessage) <-chan *command_utils.CommandMessage {
commandChannel := c.SetCommandChannel(message)
go func() {
err := c.publisher.Publish(ctx, message, c.GetName())
if err != nil {
//we can retry that .
errMessage := command_utils.NewCommandMessage("", command_utils.GetCommandStatusFromError(err),
nil)
c.DeleteCommandChannel(errMessage)
}
fmt.Printf("new message has sent from gateway into %s queue \n ", c.GetName())
}()
return commandChannel
}
func NewSignUpCommand(publisher publisher.CommandPublisher) *SignUp {
return &SignUp{
Name: broker_utils.SignUp,
DoneName: broker_utils.DoneSignUp,
publisher: publisher,
ChannelCommandManager: newCommandChannelManager(),
}
}