This commit is contained in:
shoopea 2019-06-02 18:33:55 +08:00
parent 8bd1f9e36e
commit 1545bd8915
3 changed files with 21 additions and 6 deletions

8
job.go
View File

@ -107,10 +107,12 @@ func loadCurrentJobs() ([]Job, error) {
jobs []Job jobs []Job
) )
_, err := db.Exec("UPDATE obj_job j SET j.pulled = ?, j.in_work = 1 WHERE j.is_done = 0 AND j.in_work = 0 AND j.schedule <= ? ORDER BY j.priority ASC, j.obj_id ASC LIMIT ?;", time.Now(), time.Now(), SQLJobSliceSize) t := time.Now()
_, err := db.Exec("UPDATE obj_job j SET j.pulled = ?, j.in_work = 1 WHERE j.is_done = 0 AND j.in_work = 0 AND j.schedule <= ? ORDER BY j.priority ASC, j.obj_id ASC LIMIT ?;", t, t, SQLJobSliceSize)
logOnError(err, "loadCurrentJobs : update intial rows") logOnError(err, "loadCurrentJobs : update intial rows")
stmt, err := db.Prepare("SELECT o.id, o.obj_sub_type_id, j.status, j.user_id, j.payload FROM obj_job j, obj o WHERE j.obj_id = o.id AND j.is_done = 0 AND j.in_work = 1 ORDER BY j.priority ASC, j.obj_id ASC;") stmt, err := db.Prepare("SELECT o.id, o.obj_sub_type_id, j.status, j.user_id, j.payload FROM obj_job j, obj o WHERE j.obj_id = o.id AND j.is_done = 0 AND j.in_work = 1 AND j.pulled = ? ORDER BY j.priority ASC, j.obj_id ASC;")
logOnError(err, "loadCurrentJobs : prepare select statement") logOnError(err, "loadCurrentJobs : prepare select statement")
rows, err := stmt.Query() rows, err := stmt.Query()
@ -118,7 +120,7 @@ func loadCurrentJobs() ([]Job, error) {
logOnError(err, "loadCurrentJobs : query select statement") logOnError(err, "loadCurrentJobs : query select statement")
for rows.Next() { for rows.Next() {
err = rows.Scan(&objId, &jobTypeId, &status, &userID64, &payload) err = rows.Scan(&objId, &jobTypeId, &status, &userID64, &payload, &t)
logOnError(err, "loadCurrentJobs : scan query rows") logOnError(err, "loadCurrentJobs : scan query rows")
job := Job{ job := Job{
ID64: objId, ID64: objId,

17
msg.go
View File

@ -32,12 +32,23 @@ func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStock, error) { func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStock, error) {
cwm := ChatWarsMessageStock{} cwm := ChatWarsMessageStock{}
log.Printf("parseSubTypeMessageGStockAnyAck : GStock Any Ack identified\n") items := make([]ChatWarsItems)
// log.Printf("parseSubTypeMessageGStockAnyAck : Stock : %s\n", r.ReplaceAllString(m.Text, "${Stock}"))
re := regexp.MustCompile(`\n([0-9a-z]+) (.*) x ([0-9]+)`) re := regexp.MustCompile(`\n([0-9a-z]+) (.*) x ([0-9]+)`)
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Stock}"), -1) { for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Stock}"), -1) {
log.Printf("parseSubTypeMessageGStockAnyAck : %q\n", l) i := getObjItemID(l[1])
if i == 0 {
getObjItemID(l[2])
} }
q, _ := strconv.ParseInt(l[3], 10, 64)
if i != 0 {
item := ChatWarsItems{
ItemID64: i,
Quantity: q,
}
items.Append(item)
}
}
cwm.ItemList = items
return &cwm, nil return &cwm, nil
} }

View File

@ -220,6 +220,8 @@ func SQLJobWorker() {
} }
if len(jobs) < SQLJobSliceSize { if len(jobs) < SQLJobSliceSize {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
} else {
time.Sleep(1 * time.Millisecond)
} }
} }
log.Printf("SQLJobWorker : Closing.") log.Printf("SQLJobWorker : Closing.")