test callbacks
This commit is contained in:
parent
41f02309d5
commit
e549468f9c
14
def.go
14
def.go
@ -235,8 +235,16 @@ type JobPayloadGStock struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type JobPayloadGDeposit struct {
|
type JobPayloadGDeposit struct {
|
||||||
MsgID64 int64 `json:"msg_id"`
|
MsgID64 int64 `json:"msg_id"`
|
||||||
ChatID64 int64 `json:"chat_id"`
|
ChatID64 int64 `json:"chat_id"`
|
||||||
|
ResObjID64 []int64 `json:"res_obj_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type JobPayloadSaveRes struct {
|
||||||
|
MsgID64 int64 `json:"msg_id"`
|
||||||
|
ChatID64 int64 `json:"chat_id"`
|
||||||
|
ResObjID64 int64 `json:"res_obj_id"`
|
||||||
|
BuyRes bool `json:"buy_res"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JobPayloadRescanMsg struct {
|
type JobPayloadRescanMsg struct {
|
||||||
@ -383,6 +391,7 @@ const (
|
|||||||
objSubTypeJobBackupExport = 610
|
objSubTypeJobBackupExport = 610
|
||||||
objSubTypeJobBackupImport = 611
|
objSubTypeJobBackupImport = 611
|
||||||
objSubTypeJobGDeposit = 612
|
objSubTypeJobGDeposit = 612
|
||||||
|
objSubTypeJobSaveRes = 613
|
||||||
objSubTypeItemResource = 701
|
objSubTypeItemResource = 701
|
||||||
objSubTypeItemAlch = 702
|
objSubTypeItemAlch = 702
|
||||||
objSubTypeItemMisc = 703
|
objSubTypeItemMisc = 703
|
||||||
@ -399,6 +408,7 @@ const (
|
|||||||
objSubTypeQuestSwamp = 1302
|
objSubTypeQuestSwamp = 1302
|
||||||
objSubTypeQuestValley = 1303
|
objSubTypeQuestValley = 1303
|
||||||
|
|
||||||
|
objJobStatusCallBack = -1
|
||||||
objJobStatusNew = 0
|
objJobStatusNew = 0
|
||||||
objJobStatusPillageGo = 1
|
objJobStatusPillageGo = 1
|
||||||
objJonStatusPending = 10
|
objJonStatusPending = 10
|
||||||
|
15
job.go
15
job.go
@ -54,6 +54,21 @@ func createJob(jobTypeID int32, priority int32, userID64 int64, schedule time.Ti
|
|||||||
return objId, nil
|
return objId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createJobCallback(jobTypeID int32, userID64 int64, msgTypeID64 int64, payload []byte) error {
|
||||||
|
jobID64, err := createJob(jobTypeID, userID64, time.Parse(time.RFC3339, "9999-12-31T00:00:00+00:00"), payload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
setJobCallback(jobID64, userID64, msgTypeID64)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func setJobCallback(jobID64 int64, userID64 int64, msgTypeID64 int64) {
|
||||||
|
muxCallbacks.Lock()
|
||||||
|
callbacks = append(callbacks[userID64][msgTypeID64], jobID64)
|
||||||
|
muxCallbacks.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
func setJobDone(jobId int64) error {
|
func setJobDone(jobId int64) error {
|
||||||
stmt, err := db.Prepare(`UPDATE obj_job j SET j.is_done = 1, j.in_work = 0, j.ended = ? WHERE j.obj_id = ?;`)
|
stmt, err := db.Prepare(`UPDATE obj_job j SET j.is_done = 1, j.in_work = 0, j.ended = ? WHERE j.obj_id = ?;`)
|
||||||
logOnError(err, "setJobDone : prepare update obj_job")
|
logOnError(err, "setJobDone : prepare update obj_job")
|
||||||
|
3
main.go
3
main.go
@ -63,6 +63,9 @@ var (
|
|||||||
|
|
||||||
clients map[int64]*ChirpClient
|
clients map[int64]*ChirpClient
|
||||||
muxClients sync.RWMutex
|
muxClients sync.RWMutex
|
||||||
|
|
||||||
|
callbacks map[int64][int64][]int64
|
||||||
|
muxCallbacks sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func PrintText(m *tb.Message) {
|
func PrintText(m *tb.Message) {
|
||||||
|
1
sql.go
1
sql.go
@ -495,6 +495,7 @@ func initDB() {
|
|||||||
,(` + strconv.Itoa(objSubTypeJobBackupExport) + `, "job_backup_export", "Export Backup", ` + strconv.Itoa(objTypeJob) + `)
|
,(` + strconv.Itoa(objSubTypeJobBackupExport) + `, "job_backup_export", "Export Backup", ` + strconv.Itoa(objTypeJob) + `)
|
||||||
,(` + strconv.Itoa(objSubTypeJobBackupImport) + `, "job_backup_import", "Import Backup", ` + strconv.Itoa(objTypeJob) + `)
|
,(` + strconv.Itoa(objSubTypeJobBackupImport) + `, "job_backup_import", "Import Backup", ` + strconv.Itoa(objTypeJob) + `)
|
||||||
,(` + strconv.Itoa(objSubTypeJobGDeposit) + `, "job_gdeposit", "GDeposit job", ` + strconv.Itoa(objTypeJob) + `)
|
,(` + strconv.Itoa(objSubTypeJobGDeposit) + `, "job_gdeposit", "GDeposit job", ` + strconv.Itoa(objTypeJob) + `)
|
||||||
|
,(` + strconv.Itoa(objSubTypeJobSaveRes) + `, "job_save_res", "Save resources job", ` + strconv.Itoa(objTypeJob) + `)
|
||||||
,(` + strconv.Itoa(objSubTypeItemResource) + `, "item_res", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
,(` + strconv.Itoa(objSubTypeItemResource) + `, "item_res", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
||||||
,(` + strconv.Itoa(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
,(` + strconv.Itoa(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
||||||
,(` + strconv.Itoa(objSubTypeItemMisc) + `, "item_misc", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
,(` + strconv.Itoa(objSubTypeItemMisc) + `, "item_misc", "Time", ` + strconv.Itoa(objTypeItem) + `)
|
||||||
|
@ -468,6 +468,15 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
|||||||
default:
|
default:
|
||||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID, objId, m.Text)
|
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID, objId, m.Text)
|
||||||
}
|
}
|
||||||
|
muxCallbacks.Lock()
|
||||||
|
if len(callbacks[m.TGUserID64][msgParsingRules[i].MsgTypeID]) > 0 {
|
||||||
|
for jobID64 := range callbacks[m.TGUserID64][msgParsingRules[i].MsgTypeID] {
|
||||||
|
err := rescheduleJob(jobID64, objJobStatusNew, time.Now().UTC())
|
||||||
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : callbacks triggering")
|
||||||
|
}
|
||||||
|
callbacks[m.TGUserID64][msgParsingRules[i].MsgTypeID] = new([]int64)
|
||||||
|
}
|
||||||
|
muxCallbacks.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user