From fbe5d028e5ea14d08a5d4d27199e4d0bfad7ce3e Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 11 May 2019 11:15:42 +0800 Subject: [PATCH] test --- bot.go | 15 ++++++++------- def.go | 13 ++++++++----- sql.go | 12 ++++++------ workers.go | 7 +++++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/bot.go b/bot.go index de37b6f..83f4de5 100644 --- a/bot.go +++ b/bot.go @@ -44,6 +44,8 @@ func StartBot() { b.Handle(tb.OnQuery, botQuery) b.Handle(tb.OnText, botText) + b.Send("tiennou", "test") + b.Start() } @@ -89,10 +91,8 @@ func botMsgRescan(m *tb.Message) (string, error) { } r := regexp.MustCompile("^[0-9]+$") if r.MatchString(m.Payload) { - msgID64, _ := strconv.ParseInt(m.Payload, 10, 64) - p := JobPayloadRescanMsg{ - MsgID64: msgID64, - } + p := JobPayloadRescanMsg{} + fmt.Sprintf(p.Query, "SELECT o.id from obj o where o.id = %d and o.obj_type_id = %d and o.obj_sub_type_id = %d;", m.Payload, objTypeMessage, objSubTypeMessageUnprocessed) b, _ := json.Marshal(p) err := createJob(objSubTypeJobRescanMsg, 2, time.Now(), b) logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)") @@ -105,10 +105,11 @@ func botMsgRescan(m *tb.Message) (string, error) { } r = regexp.MustCompile("^all$") if r.MatchString(m.Payload) { - p := JobPayloadRescanAllMsg{} + p := JobPayloadRescanMsg{} + fmt.Sprintf(p.Query, "SELECT o.id from obj o where o.obj_type_id = %d and o.obj_sub_type_id = %d;", objTypeMessage, objSubTypeMessageUnprocessed) b, _ := json.Marshal(p) - err := createJob(objSubTypeJobRescanAllMsg, 3, time.Now(), b) - logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanAllMsg)") + err := createJob(objSubTypeJobRescanMsg, 3, time.Now(), b) + logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)") if err != nil { return "Error scheduling the rescan for all msg", nil } else { diff --git a/def.go b/def.go index 77f4529..18dfda6 100644 --- a/def.go +++ b/def.go @@ -1,6 +1,7 @@ package main import ( + tb "gopkg.in/tucnak/telebot.v2" "regexp" "time" ) @@ -36,6 +37,11 @@ type MessageParsingRule struct { re *regexp.Regexp } +type BotMsg struct { + To tb.Recipient + Text string +} + type Job struct { ID64 int64 JobTypeID int32 @@ -63,10 +69,7 @@ type JobPayloadGStock struct { } type JobPayloadRescanMsg struct { - MsgID64 int64 `json:"msg_id"` -} - -type JobPayloadRescanAllMsg struct { + Query string `json:"query"` } const ( @@ -103,7 +106,7 @@ const ( objSubTypeJobWithdrawal = 604 objSubTypeJobGStock = 605 objSubTypeJobRescanMsg = 606 - objSubTypeJobRescanAllMsg = 607 + objSubTypeJobMarkAsDone = 607 objSubTypeItemResource = 701 objSubTypeItemAlch = 702 objSubTypeItemMisc = 703 diff --git a/sql.go b/sql.go index bdffc64..fc343c2 100644 --- a/sql.go +++ b/sql.go @@ -236,11 +236,11 @@ func initDB() { ,(` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "auction_announce", "Auction announce", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeMessageTime) + `, "time", "Time", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeJobPillage) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `) - ,(` + strconv.Itoa(objSubTypeJobTribute) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `) - ,(` + strconv.Itoa(objSubTypeJobWithdrawal) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `) - ,(` + strconv.Itoa(objSubTypeJobGStock) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `) - ,(` + strconv.Itoa(objSubTypeJobRescanMsg) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `) - ,(` + strconv.Itoa(objSubTypeJobRescanAllMsg) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `) + ,(` + strconv.Itoa(objSubTypeJobTribute) + `, "job_tribute", "Tribute job", ` + strconv.Itoa(objTypeJob) + `) + ,(` + strconv.Itoa(objSubTypeJobWithdrawal) + `, "job_withdraw", "Withdrawal job", ` + strconv.Itoa(objTypeJob) + `) + ,(` + strconv.Itoa(objSubTypeJobGStock) + `, "job_gstock", "GStock job", ` + strconv.Itoa(objTypeJob) + `) + ,(` + strconv.Itoa(objSubTypeJobRescanMsg) + `, "job_rescan_msg", "Rescan message job", ` + strconv.Itoa(objTypeJob) + `) + ,(` + strconv.Itoa(objSubTypeJobMarkAsDone) + `, "job_mark_as_done", "Mark job as done job", ` + strconv.Itoa(objTypeJob) + `) ,(` + strconv.Itoa(objSubTypeItemResource) + `, "item_res", "Time", ` + strconv.Itoa(objTypeItem) + `) ,(` + strconv.Itoa(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `) ,(` + strconv.Itoa(objSubTypeItemMisc) + `, "item_misc", "Time", ` + strconv.Itoa(objTypeItem) + `) @@ -1431,7 +1431,7 @@ func loadCurrentJobs() ([]Job, error) { } defer tx.Rollback() - stmt, err := tx.Prepare("SELECT o.id, o.obj_sub_type_id, j.payload FROM obj_job j, obj o WHERE j.obj_id = o.id AND j.status = ? AND j.schedule <= ? ORDER BY j.priority ASC LIMIT ? FOR UPDATE;") + stmt, err := tx.Prepare("SELECT o.id, o.obj_sub_type_id, j.payload FROM obj_job j, obj o WHERE j.obj_id = o.id AND j.status = ? AND j.schedule <= ? ORDER BY j.priority ASC, j.obj_id ASC LIMIT ? FOR UPDATE;") logOnError(err, "loadCurrentJobs : prepare select statement") rows, err := stmt.Query(objJobStatusNew, time.Now(), SQLJobSliceSize) diff --git a/workers.go b/workers.go index 2b6b24f..bcc3322 100644 --- a/workers.go +++ b/workers.go @@ -145,6 +145,9 @@ func SQLJobWorker(id int) { logOnError(err, "SQLJobWorker["+strconv.Itoa(id)+"] : loadCurrentJobs") if len(jobs) > 0 { log.Printf("SQLJobWorker["+strconv.Itoa(id)+"] : %d jobs.\n", len(jobs)) + } + for _, j := range jobs { + } if len(jobs) < SQLJobSliceSize { time.Sleep(100 * time.Millisecond) @@ -152,3 +155,7 @@ func SQLJobWorker(id int) { } log.Printf("SQLJobWorker[" + strconv.Itoa(id) + "] : Closing.") } + +/* +func BotMsgWorker(id int, botMsg <-chan +*/