Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Aug 5, 2024
1 parent c2fb315 commit 5bc8933
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
6 changes: 4 additions & 2 deletions service/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ func NewServices(repository *repository.Repository) Services {
eventTypeService := NewEventTypeService(repository)
actionTypeService := NewActionTypeService(repository)

eventServiceWS := NewEventServiceWS(eventTypeService)

return Services{
EventTypeService: eventTypeService,
EventServiceWS: NewEventServiceWS(eventTypeService),
SocketIOService: NewSocketIOService(),
EventServiceWS: eventServiceWS,

ActionTypeService: actionTypeService,
ActionServiceWS: NewActionServiceWS(actionTypeService),
YSKService: NewYSKService(repository),
YSKService: NewYSKService(repository, eventServiceWS),
}
}
28 changes: 27 additions & 1 deletion service/ysk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ package service

import (
"context"
"fmt"
"log"

"github.com/IceWhaleTech/CasaOS-MessageBus/pkg/ysk"
"github.com/IceWhaleTech/CasaOS-MessageBus/repository"
)

type YSKService struct {
repository *repository.Repository
ws *EventServiceWS
}

func NewYSKService(repository *repository.Repository) *YSKService {
func NewYSKService(repository *repository.Repository, ws *EventServiceWS) *YSKService {
return &YSKService{
repository: repository,
ws: ws,
}
}

Expand All @@ -37,3 +41,25 @@ func (s *YSKService) UpsertYSKCard(ctx context.Context, yskCard ysk.YSKCard) err
func (s *YSKService) DeleteYSKCard(ctx context.Context, id string) error {
return nil
}

func (s *YSKService) Start() {
channel, err := s.ws.Subscribe(ysk.SERVICENAME, []string{
"ysk:card:create", "ysk:card:delete",
})
if err != nil {
return
}

go func() {
for {
select {
case event, ok := <-channel:
if !ok {
log.Println("channel closed")
}
fmt.Println(event)
}
}
}()

}
6 changes: 4 additions & 2 deletions service/ysk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func setup(t *testing.T) (*service.YSKService, func()) {
repository, err := repository.NewDatabaseRepositoryInMemory()
assert.NilError(t, err)

yskService := service.NewYSKService(&repository)
yskService := service.NewYSKService(&repository, nil)
return yskService, func() {
repository.Close()
}
Expand Down Expand Up @@ -62,7 +62,9 @@ func TestInsertAllTypeCardList(t *testing.T) {
assert.Equal(t, len(cardList), 0)

cardInsertQueue := []ysk.YSKCard{
utils.ApplicationInstallProgress, utils.DiskInsertNotice, utils.ApplicationUpdateNotice,
utils.ApplicationInstallProgress, utils.DiskInsertNotice,
// the notice is short. it didn't be stored
utils.ApplicationUpdateNotice,
utils.ApplicationInstallProgress.WithProgress("Installing LinuxServer/Jellyfin", 50), utils.ApplicationInstallProgress.WithProgress("Installing LinuxServer/Jellyfin", 55),
utils.ApplicationInstallProgress.WithProgress("Installing LinuxServer/Jellyfin", 80), utils.ApplicationInstallProgress.WithProgress("Installing LinuxServer/Jellyfin", 99),
utils.ApplicationUpdateNotice,
Expand Down

0 comments on commit 5bc8933

Please sign in to comment.