go_dreamfactory/modules/model/dbservice_comp.go
2022-06-13 17:40:10 +08:00

40 lines
752 B
Go

package model
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"time"
)
type DBService_Comp struct {
cbase.ModuleCompBase
task chan string
DB_Comp
}
func (this *DBService_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options)
return
}
func (this *DBService_Comp) Start(err error) {
this.ModuleCompBase.Start()
go this.run()
}
func (this *DBService_Comp) run() {
for {
select {
case v := <-this.task:
this.Model_UpdateUserDataByUid(v)
case <-time.After(time.Second):
this.Model_UpdateDBBylog()
}
}
}
func (this *DBService_Comp) PushUserTask(uid string) {
this.task <- uid
}