sqs-browse: a lot of work to try to keep UI complexity down
Added the notion of controllers and a dispatcher which will queue up operations
This commit is contained in:
parent
1969504611
commit
7526c095ee
24 changed files with 602 additions and 97 deletions
39
internal/sqs-browse/controllers/forward.go
Normal file
39
internal/sqs-browse/controllers/forward.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/lmika/awstools/internal/common/ui/uimodels"
|
||||
"github.com/lmika/awstools/internal/sqs-browse/models"
|
||||
"github.com/lmika/awstools/internal/sqs-browse/services/messages"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type MessageSendingController struct {
|
||||
messageService *messages.Service
|
||||
targetQueue string
|
||||
}
|
||||
|
||||
func NewMessageSendingController(messageService *messages.Service, targetQueue string) *MessageSendingController {
|
||||
return &MessageSendingController{
|
||||
messageService: messageService,
|
||||
targetQueue: targetQueue,
|
||||
}
|
||||
}
|
||||
|
||||
func (msh *MessageSendingController) ForwardMessage(message models.Message) uimodels.Operation {
|
||||
return uimodels.OperationFn(func(ctx context.Context) error {
|
||||
uiCtx := uimodels.Ctx(ctx)
|
||||
|
||||
if msh.targetQueue == "" {
|
||||
return errors.New("target queue not set")
|
||||
}
|
||||
|
||||
messageId, err := msh.messageService.SendTo(ctx, message, msh.targetQueue)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "cannot send message to %v", msh.targetQueue)
|
||||
}
|
||||
|
||||
uiCtx.Message("Message sent to " + msh.targetQueue + ", id = " + messageId)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue