chirpnest/job.go

121 lines
3.1 KiB
Go
Raw Normal View History

2019-05-11 06:54:12 +02:00
package main
import (
2019-05-11 06:55:05 +02:00
"encoding/json"
2019-05-11 06:54:12 +02:00
"fmt"
2019-05-11 06:55:05 +02:00
"time"
2019-05-11 06:54:12 +02:00
)
2019-05-11 06:54:49 +02:00
func jobRescan(j Job) {
2019-05-11 07:06:40 +02:00
var r JobPayloadRescanMsg
2019-05-11 06:54:12 +02:00
err := setJobStart(j.ID64)
logOnError(err, "jobRescan : setJobStart")
2019-05-11 07:06:40 +02:00
2019-05-11 06:56:48 +02:00
err = json.Unmarshal(j.Payload, &r)
2019-05-11 07:06:40 +02:00
logOnError(err, "jobRescan : Unmarshal payload")
2019-05-19 05:24:45 +02:00
start := time.Now()
2019-05-11 06:54:12 +02:00
ids := getSQLListID64(r.Query)
2019-05-11 07:06:40 +02:00
2019-05-11 06:54:12 +02:00
if len(ids) > 1 {
2019-05-19 05:20:01 +02:00
for _, id := range ids {
SQLMsgIdentifyQueue <- id
2019-05-11 06:54:12 +02:00
}
2019-05-19 05:20:01 +02:00
p := JobPayloadSetDone{
JobID64: j.ID64,
MsgID64: r.MsgID64,
ChatID64: r.ChatID64,
2019-05-19 05:24:45 +02:00
Text: fmt.Sprintf("%d messages processed in %s.", len(ids), time.Since(start)),
2019-05-11 06:54:12 +02:00
}
2019-05-19 05:20:01 +02:00
b, _ := json.Marshal(p)
err := createJob(objSubTypeJobSetJobDone, objJobPriorityRescanAllMsg, j.UserID64, time.Now(), b)
logOnError(err, "jobRescan : createJob(objSubTypeJobSetJobDone)")
2019-05-11 06:54:12 +02:00
} else if len(ids) == 1 {
SQLMsgIdentifyQueue <- ids[0]
err = setJobDone(j.ID64)
2019-05-11 07:06:40 +02:00
logOnError(err, "jobRescan : setJobDone(1)")
2019-05-16 05:06:38 +02:00
if r.MsgID64 != 0 || r.ChatID64 != 0 {
m := TGCommand{
Type: commandReplyMsg,
Text: "One message processed.",
FromMsgID64: r.MsgID64,
FromChatID64: r.ChatID64,
}
TGCmdQueue <- m
2019-05-16 04:49:34 +02:00
}
2019-05-11 07:06:40 +02:00
} else {
err = setJobDone(j.ID64)
logOnError(err, "jobRescan : setJobDone(0)")
2019-05-16 05:06:38 +02:00
if r.MsgID64 != 0 || r.ChatID64 != 0 {
m := TGCommand{
Type: commandReplyMsg,
2019-05-16 05:11:56 +02:00
Text: "No message processed.",
2019-05-16 05:06:38 +02:00
FromMsgID64: r.MsgID64,
FromChatID64: r.ChatID64,
}
TGCmdQueue <- m
2019-05-16 04:49:34 +02:00
}
2019-05-11 06:54:12 +02:00
}
return
}
2019-05-11 06:54:49 +02:00
func jobSetDone(j Job) {
2019-05-11 07:06:40 +02:00
var r JobPayloadSetDone
2019-05-11 06:54:12 +02:00
err := setJobStart(j.ID64)
logOnError(err, "jobSetDone : setJobStart")
2019-05-11 07:06:40 +02:00
2019-05-11 06:56:48 +02:00
err = json.Unmarshal(j.Payload, &r)
2019-05-11 07:06:40 +02:00
logOnError(err, "jobSetDone : Unmarshal payload")
2019-05-11 06:54:12 +02:00
err = setJobDone(r.JobID64)
logOnError(err, "jobSetDone : setJobDone(child)")
2019-05-11 07:06:40 +02:00
2019-05-11 06:54:12 +02:00
err = setJobDone(j.ID64)
logOnError(err, "jobSetDone : setJobDone")
2019-05-11 07:06:40 +02:00
2019-05-16 04:52:30 +02:00
m := TGCommand{
Type: commandReplyMsg,
Text: r.Text,
FromMsgID64: r.MsgID64,
FromChatID64: r.ChatID64,
}
TGCmdQueue <- m
2019-05-11 06:54:12 +02:00
return
}
2019-05-16 14:39:12 +02:00
func jobPillage(j Job) {
2019-05-18 12:33:53 +02:00
/*
2019-05-19 04:54:34 +02:00
var r JobPayloadPillage
err := setJobStart(j.ID64)
logOnError(err, "jobPillage : setJobStart")
err = json.Unmarshal(j.Payload, &r)
logOnError(err, "jobPillage : Unmarshal payload")
ids := getSQLListID64(` select og.id
from obj og
,obj_msg omg
,obj op
,obj_msg omp
,obj_job oj
where omg.obj_id = og.id
and og.obj_sub_type_id = ` + strconv.Itoa(objSubTypeMessageGo) `
and omg.user_id = oj.user_id
and omg.sender_user_id = oj.user_id
and oj.obj_id = ` + strconv.Itoa(j.ID64) `
and omp.obj_id = op.id
and op.id = ` + strconv.Itoa(r.ObjID64) `
and omg.date between omp.date and addtime(omp.date, '0 0:3:0.000000');`
err = setJobStatus(j.ID64, objJobStatusPillageGo, time.Now().Add(5 * time.second))
logOnError(err, "jobPillage : setJobDone")
2019-05-18 12:33:53 +02:00
*/
2019-05-16 14:39:12 +02:00
return
}