This commit is contained in:
shoopea 2019-06-10 20:31:59 +08:00
parent 019c680fe7
commit 99a89f5d86
3 changed files with 15 additions and 11 deletions

2
def.go
View File

@ -347,6 +347,8 @@ const (
objSubTypeJobSetJobDone = 607
objSubTypeJobMsgClient = 608
objSubTypeJobMsgRefresh = 609
objSubTypeJobExportBackup = 610
objSubTypeJobImportBackup = 611
objSubTypeItemResource = 701
objSubTypeItemAlch = 702
objSubTypeItemMisc = 703

10
job.go
View File

@ -38,7 +38,7 @@ func createJob(jobTypeID int32, priority int32, userID64 int64, schedule time.Ti
}
defer stmt.Close()
_, err = stmt.Exec(objId, priority, userID64, objJobStatusNew, schedule, time.Now(), payload)
_, err = stmt.Exec(objId, priority, userID64, objJobStatusNew, schedule.UTC(), time.Now().UTC(), payload)
logOnError(err, "createJob : insert obj_job")
if err != nil {
return 0, err
@ -55,7 +55,7 @@ func setJobDone(jobId int64) error {
}
defer stmt.Close()
_, err = stmt.Exec(time.Now(), jobId)
_, err = stmt.Exec(time.Now().UTC(), jobId)
s := fmt.Sprintf("setJobDone, update obj_job(%d)", jobId)
logOnError(err, s)
if err != nil {
@ -72,7 +72,7 @@ func setJobStart(jobId int64) error {
}
defer stmt.Close()
_, err = stmt.Exec(time.Now(), jobId)
_, err = stmt.Exec(time.Now().UTC(), jobId)
s := fmt.Sprintf("setJobStart, update obj_job(%d)", jobId)
logOnError(err, s)
if err != nil {
@ -89,7 +89,7 @@ func rescheduleJob(jobID64 int64, status int32, schedule time.Time) error {
}
defer stmt.Close()
_, err = stmt.Exec(schedule, status, jobID64)
_, err = stmt.Exec(schedule.UTC(), status, jobID64)
s := fmt.Sprintf("rescheduleJob, update obj_job(%d)", jobID64)
logOnError(err, s)
if err != nil {
@ -375,6 +375,8 @@ func jobMsgRefresh(j Job) {
err = delObj(p.ObjID64)
logOnError(err, "jobMsgRefresh : delObj")
log.Printf("Refreshing message :\n%s\n", m.Text)
c := TGCommand{
Type: commandRefreshMsg,
FromChatID64: m.ChatID64,

14
obj.go
View File

@ -75,7 +75,6 @@ func addObjMsg(msgID64 int64, msgChatID64 int64, msgUserID64 int64, msgSenderUse
res, err := tx.Exec(`INSERT INTO obj (obj_type_id, obj_sub_type_id)
VALUES (` + strconv.Itoa(objTypeMessage) + `,` + strconv.Itoa(objSubTypeMessageUnknown) + `);`)
logOnError(err, "addObjMsg : exec insert obj")
if err != nil {
err2 := tx.Rollback()
logOnError(err2, "addObjMsg : rollback insert obj")
@ -91,7 +90,6 @@ func addObjMsg(msgID64 int64, msgChatID64 int64, msgUserID64 int64, msgSenderUse
stmt, err := tx.Prepare(`INSERT INTO obj_msg (obj_id, msg_id, chat_id, user_id, sender_user_id, date, text)
VALUES (?, ?, ?, ?, ?, ?, ?);`)
logOnError(err, "addObjMsg : prepare insert obj_msg")
if err != nil {
err2 := tx.Rollback()
logOnError(err2, "addObjMsg : rollback prepare insert obj_msg")
@ -100,7 +98,6 @@ func addObjMsg(msgID64 int64, msgChatID64 int64, msgUserID64 int64, msgSenderUse
defer stmt.Close()
_, err = stmt.Exec(objId, msgID64, msgChatID64, msgUserID64, msgSenderUserID64, msgDate, msgText)
logOnError(err, "addObjMsg : exec insert obj_msg")
if err != nil {
err2 := tx.Rollback()
logOnError(err2, "addObjMsg : rollback exec insert obj_msg")
@ -108,7 +105,6 @@ func addObjMsg(msgID64 int64, msgChatID64 int64, msgUserID64 int64, msgSenderUse
}
err = tx.Commit()
logOnError(err, "addObjMsg : commit")
if err != nil {
return 0, err
}
@ -168,6 +164,8 @@ func delObj(objId int64) error {
return errors.New("Can only delete objSubTypeMessageAuctionAnnounce.")
}
cacheObjMsg.Delete(objId) // better delete from cache before, worst case we reload after
stmt, err := db.Prepare(`DELETE FROM obj WHERE id = ?`)
if err != nil {
return err
@ -184,9 +182,11 @@ func delObj(objId int64) error {
return err
}
log.Printf("delObj : %d RowsAffected.\n", count)
cacheObjMsg.Delete(objId)
if count > 1 {
return errors.New("More than one row impacted.")
} else if count == 0 {
return errors.New("No row impacted.")
}
return nil
}