initiate jobGStock

This commit is contained in:
shoopea 2019-08-08 20:39:23 +08:00
parent 332236588a
commit c84c29ccc5
4 changed files with 53 additions and 12 deletions

24
bot.go
View File

@ -234,7 +234,7 @@ func botMsgRescan(m *tb.Message) {
}
b, _ := json.Marshal(p)
log.Printf("botMsgRescan : json : %s\n", string(b))
_, err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanMsg, int64(m.Sender.ID), time.Now(), b)
_, err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanMsg, int64(m.Sender.ID), time.Now().UTC(), b)
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)")
if err != nil {
c := TGCommand{
@ -293,7 +293,7 @@ func botMsgRescanAll(m *tb.Message) {
ChatID64: m.Chat.ID,
}
b, _ := json.Marshal(p)
_, err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanAllMsg, int64(m.Sender.ID), time.Now(), b)
_, err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanAllMsg, int64(m.Sender.ID), time.Now().UTC(), b)
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)")
if err != nil {
@ -348,7 +348,7 @@ func botBackupExport(m *tb.Message) {
ChatID64: m.Chat.ID,
}
b, _ := json.Marshal(p)
_, err := createJob(objSubTypeJobBackupExport, objJobPriorityBackup, int64(m.Sender.ID), time.Now(), b)
_, err := createJob(objSubTypeJobBackupExport, objJobPriorityBackup, int64(m.Sender.ID), time.Now().UTC(), b)
logOnError(err, "botBackupExport : createJob(objSubTypeJobBackupExport)")
return
@ -398,7 +398,7 @@ func botBackupImport(m *tb.Message) {
ChatID64: m.Chat.ID,
}
b, _ := json.Marshal(p)
_, err := createJob(objSubTypeJobBackupImport, objJobPriorityBackup, int64(m.Sender.ID), time.Now(), b)
_, err := createJob(objSubTypeJobBackupImport, objJobPriorityBackup, int64(m.Sender.ID), time.Now().UTC(), b)
logOnError(err, "botBackupImport : createJob(objSubTypeJobBackupImport)")
return
@ -567,12 +567,14 @@ func botGStock(m *tb.Message) {
if !m.Private() {
return
}
clientSendCWMsg(m.Chat.ID, "/g_stock_res")
clientSendCWMsg(m.Chat.ID, "/g_stock_alch")
clientSendCWMsg(m.Chat.ID, "/g_stock_misc")
clientSendCWMsg(m.Chat.ID, "/g_stock_rec")
clientSendCWMsg(m.Chat.ID, "/g_stock_parts")
clientSendCWMsg(m.Chat.ID, "/g_stock_other")
p := JobPayloadGStock{
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
}
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
objID64, err := createJob(objSubTypeJobGStock, objJobPriority, int64(m.Chat.ID), t, b)
c := TGCommand{
Type: commandReplyMsg,
@ -619,7 +621,7 @@ func botTimer(m *tb.Message) {
ChatID64: m.Chat.ID,
}
b, _ := json.Marshal(p)
t := time.Now().Add(d)
t := time.Now().UTC().Add(d)
objID64, err := createJob(objSubTypeJobMsgClient, objJobPriority, int64(m.Chat.ID), t, b)
logOnError(err, "botTimer : createJob")
if err != nil {

2
def.go
View File

@ -230,6 +230,8 @@ type JobPayloadWithdrawal struct {
}
type JobPayloadGStock struct {
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
}
type JobPayloadRescanMsg struct {

30
job.go
View File

@ -652,3 +652,33 @@ func jobBackupImport(j Job) {
logOnError(err, "jobBackupImport : setJobDone")
return
}
func jobGStock(j Job) {
var p JobPayloadGStock
err := setJobStart(j.ID64)
logOnError(err, "jobGStock : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobGStock : Unmarshal payload")
/*
clientSendCWMsg(m.Chat.ID, "/g_stock_res")
clientSendCWMsg(m.Chat.ID, "/g_stock_alch")
clientSendCWMsg(m.Chat.ID, "/g_stock_misc")
clientSendCWMsg(m.Chat.ID, "/g_stock_rec")
clientSendCWMsg(m.Chat.ID, "/g_stock_parts")
clientSendCWMsg(m.Chat.ID, "/g_stock_other")
*/
if err == nil {
m := TGCommand{
Type: commandReplyMsg,
Text: "Message sent.",
FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64,
}
TGCmdQueue <- m
}
err = setJobDone(j.ID64)
logOnError(err, "jobGStock : setJobDone")
return
}

View File

@ -370,6 +370,12 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case objSubTypeMessageDepositAck:
case objSubTypeMessageStockReq:
case objSubTypeMessageMiscReq:
case objSubTypeMessageGStockResReq:
case objSubTypeMessageGStockAlchReq:
case objSubTypeMessageGStockMiscReq:
case objSubTypeMessageGStockRecReq:
case objSubTypeMessageGStockPartReq:
case objSubTypeMessageGStockOthReq:
case objSubTypeMessageGStockAnyAck:
_, err := parseSubTypeMessageGStockAnyAck(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageGStockAnyAck.")
@ -506,7 +512,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobBackupExport(j)
case objSubTypeJobBackupImport:
jobBackupImport(j)
case objSubTypeJobGStock:
jobGStock(j)
default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
}