go_dreamfactory/modules/model/dbservice_comp.go
2022-06-14 19:32:02 +08:00

41 lines
841 B
Go

package model
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"time"
)
type DBService_Comp struct {
cbase.ModuleCompBase
task chan string
module *Model
}
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)
this.module = module.(*Model)
return
}
func (this *DBService_Comp) Start() (err error) {
err = this.ModuleCompBase.Start()
go this.run()
return
}
func (this *DBService_Comp) run() {
for {
select {
case v := <-this.task:
this.module.db_comp.Model_UpdateUserDataByUid(v)
case <-time.After(time.Second * 2):
this.module.db_comp.Model_UpdateDBByLog()
}
}
}
func (this *DBService_Comp) PushUserTask(uid string) {
this.task <- uid
}