chirpnest/job.go
2019-05-11 12:55:05 +08:00

48 lines
1.3 KiB
Go

package main
import (
"encoding/json"
"fmt"
"time"
)
func jobRescan(j Job) {
err := setJobStart(j.ID64)
logOnError(err, "jobRescan : setJobStart")
r := JobPayloadRescanMsg{}
err = json.Unmarshal(j.payload, &r)
ids := getSQLListID64(r.Query)
if len(ids) > 1 {
for _, id := range ids {
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;", id, objTypeMessage, objSubTypeMessageUnknown)
b, _ := json.Marshal(p)
err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanChildMsg, time.Now(), b)
logOnError(err, "jobRescan : createJob(objSubTypeJobRescanMsg)")
}
p := JobPayloadSetDone{
JobID64: j.ID64,
}
b, _ := json.Marshal(p)
err := createJob(objSubTypeJobSetJobDone, objJobPriority, time.Now(), b)
logOnError(err, "jobRescan : createJob(objSubTypeJobSetJobDone)")
} else if len(ids) == 1 {
SQLMsgIdentifyQueue <- ids[0]
err = setJobDone(j.ID64)
logOnError(err, "jobRescan : setJobDone")
}
return
}
func jobSetDone(j Job) {
err := setJobStart(j.ID64)
logOnError(err, "jobSetDone : setJobStart")
r := JobPayloadSetDone{}
err = json.Unmarshal(j.payload, &r)
err = setJobDone(r.JobID64)
logOnError(err, "jobSetDone : setJobDone(child)")
err = setJobDone(j.ID64)
logOnError(err, "jobSetDone : setJobDone")
return
}