Browse Source

'fix'

master
u 2 years ago
parent
commit
855b847f09
  1. 85
      hasaki-gen-crud/template.go

85
hasaki-gen-crud/template.go

@ -1,8 +1,12 @@
package main
import (
"fmt"
"time"
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb"
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskgin"
"git.ouxuan.net/hasaki-service/hasaki-sdk/hsklogger/L"
"xorm.io/builder"
"xorm.io/xorm"
)
@ -10,6 +14,7 @@ import (
type Temp3A60 struct {
Id int
service string
QueueStatus string
}
// ----------------------------temp------------------------------------
@ -79,6 +84,26 @@ func (TempLowHead3A60 *Temp3A60) getXorm() *xorm.Engine {
return hskdb.GetXormAuto()
}
// 队列状态
const (
Temp3A60QueueWait = 2 * time.Second
Temp3A60QueueStatusNone = "None"
Temp3A60QueueStatusIng = "Ing"
Temp3A60QueueStatusSuccess = "Success"
Temp3A60QueueStatusFail = "Fail"
)
// 不同service对应的不同队列状态
var Temp3A60QueueStatusFieldMap = map[string]string{
"service": "queue_status",
}
// 队列事件
func (TempLowHead3A60 *Temp3A60) queueEvent() error {
//todo
return nil
}
// ----------------------------temp------------------------------------
// Save 保存或者新增,通过wherePrimaryKey查不到数据时,新增数据,否则修改数据,参数:isAllCols...
@ -253,6 +278,64 @@ func (TempLowHead3A60 *Temp3A60) Delete() (err error) {
// ----------------------------temp------------------------------------
func StartQueueTaskPrefixHigHead3A60Temp3A60() {
serviceName := "Prefix3A60"
f := Temp3A60QueueStatusFieldMap[serviceName]
go func() {
defer func() {
err := recover()
if err != nil {
L.Error("StartQueueTaskPrefixHigHead3A60Temp3A60意外退出:", err)
}
time.Sleep(time.Second * 5)
StartQueueTaskPrefixHigHead3A60Temp3A60()
}()
for {
onec := &Temp3A60{}
hskdb.GetXormAuto().Where(fmt.Sprintf("`%s`=?", f), Temp3A60QueueStatusNone).OrderBy("rand()").Find(&onec)
session := onec.getXorm().NewSession()
defer session.Close()
whereQuery, whereArgs := onec.wherePrimaryKey()
whereCond := onec.wherePrimaryKeyWithCond()
if whereQuery != "" {
session = session.Where(whereQuery, whereArgs...)
}
if whereCond != nil {
session = session.Where(whereCond)
}
i, err := session.Where(fmt.Sprintf("`%s`=?", f), Temp3A60QueueStatusNone).Update(map[string]interface{}{f: Temp3A60QueueStatusIng})
if err == nil && i == 1 {
func() {
{
err := onec.queueEvent()
session := onec.getXorm().NewSession()
defer session.Close()
whereQuery, whereArgs := onec.wherePrimaryKey()
whereCond := onec.wherePrimaryKeyWithCond()
if whereQuery != "" {
session = session.Where(whereQuery, whereArgs...)
}
if whereCond != nil {
session = session.Where(whereCond)
}
if err != nil {
session.Where(fmt.Sprintf("`%s`=?", f), Temp3A60QueueStatusNone).Update(map[string]interface{}{f: Temp3A60QueueStatusFail})
} else {
session.Where(fmt.Sprintf("`%s`=?", f), Temp3A60QueueStatusNone).Update(map[string]interface{}{f: Temp3A60QueueStatusSuccess})
}
}
}()
}
time.Sleep(Temp3A60QueueWait)
}
}()
}
func InitializationHttpCrudPrefixHigHead3A60Temp3A60(router *hskgin.GinHelper, authoritys ...func(ctx *hskgin.GinContextHelper, TempLowHead3A60 *Temp3A60)) {
var authority = func(ctx *hskgin.GinContextHelper, TempLowHead3A60 *Temp3A60) {
}
@ -311,5 +394,3 @@ func InitializationHttpCrudPrefixHigHead3A60Temp3A60(router *hskgin.GinHelper, a
ctx.DisplayBySuccess("删除成功")
})
}
// ----------------------------temp------------------------------------
Loading…
Cancel
Save