backend/app/brahma/service/token/internal/server/script.go

54 lines
1.2 KiB
Go

package servesr
import (
"context"
"errors"
"git.icechen.cn/monorepo/backend/app/brahma/service/token/internal/model"
"git.icechen.cn/monorepo/backend/app/brahma/service/token/internal/pkg"
"git.icechen.cn/monorepo/backend/pkg/orm"
"git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders"
"git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/script"
"time"
)
type Script struct {
murders.UnimplementedMurdersServer
pkg.WorkerInterFace
queryMap *murders.QueryCondition
scriptModel *[]model.Scripts
}
func (s *Script) GetScripts(ctx context.Context, queryMap *murders.QueryCondition) (*script.Scripts, error) {
s.queryMap = queryMap
err := pkg.Run(1*time.Second, ctx, s)
if err != nil {
return nil, err
}
return nil, err
}
func (s *Script) Work(ctx context.Context, finishChan chan<- pkg.Finish) {
go pkg.Watcher(ctx, finishChan)
db, err := orm.GetContextDB(ctx, orm.DB)
if err != nil {
pkg.SafeSend(finishChan, pkg.Finish{
IsDone: false,
Err: err,
})
}
i := new([]model.Scripts)
if num := db.Find(i).RowsAffected; num < 0 {
pkg.SafeSend(finishChan, pkg.Finish{
IsDone: false,
Err: errors.New("RowsAffected < 0"),
})
}
s.scriptModel = i
pkg.SafeSend(finishChan, pkg.Finish{
IsDone: true,
Err: nil,
})
}