This commit is contained in:
shoopea 2020-01-02 20:07:46 +08:00
parent 014bcb7873
commit 5aff9b0bd3
3 changed files with 22 additions and 22 deletions

12
def.go
View File

@ -318,12 +318,12 @@ type BotMsg struct {
} }
type Job struct { type Job struct {
ID64 int64 ID64 int64
JobTypeID int32 JobTypeID64 int64
Trigger int64 Trigger int64
Timeout time.Time Timeout time.Time
UserID64 int64 UserID64 int64
Payload []byte Payload []byte
} }
type JobPayloadGetHammerTime struct { type JobPayloadGetHammerTime struct {

28
job.go
View File

@ -153,13 +153,13 @@ func rescheduleJob(jobID64 int64, trigger int64, schedule time.Time) error {
func loadCurrentJobs() ([]Job, error) { func loadCurrentJobs() ([]Job, error) {
var ( var (
objId int64 objId int64
jobTypeId int32 jobTypeID64 int64
userID64 int64 userID64 int64
trigger int64 trigger int64
timeout time.Time timeout time.Time
payload []byte payload []byte
jobs []Job jobs []Job
) )
t := time.Now().UTC() t := time.Now().UTC()
@ -187,15 +187,15 @@ func loadCurrentJobs() ([]Job, error) {
} }
for rows.Next() { for rows.Next() {
err = rows.Scan(&objId, &jobTypeId, &trigger, &userID64, &payload, &timeout) err = rows.Scan(&objId, &jobTypeID64, &trigger, &userID64, &payload, &timeout)
logOnError(err, "loadCurrentJobs : scan query rows") logOnError(err, "loadCurrentJobs : scan query rows")
job := Job{ job := Job{
ID64: objId, ID64: objId,
JobTypeID: jobTypeId, JobTypeID64: jobTypeID64,
Trigger: trigger, Trigger: trigger,
UserID64: userID64, UserID64: userID64,
Payload: payload, Payload: payload,
Timeout: timeout, Timeout: timeout,
} }
jobs = append(jobs, job) jobs = append(jobs, job)
} }

View File

@ -548,7 +548,7 @@ func JobWorker(id int, jobs <-chan Job) {
for j := range jobs { for j := range jobs {
//log.Printf("JobWorker[%d] : Starting job %d (timeout : %s).\n", id, j.ID64, j.Timeout.Format(time.RFC3339)) //log.Printf("JobWorker[%d] : Starting job %d (timeout : %s).\n", id, j.ID64, j.Timeout.Format(time.RFC3339))
if time.Now().UTC().Before(j.Timeout) { if time.Now().UTC().Before(j.Timeout) {
switch j.JobTypeID { switch j.JobTypeID64 {
case cacheObjSubType[`job_rescan_msg`]: case cacheObjSubType[`job_rescan_msg`]:
jobRescan(j) jobRescan(j)
case cacheObjSubType[`job_set_done`]: case cacheObjSubType[`job_set_done`]:
@ -582,7 +582,7 @@ func JobWorker(id int, jobs <-chan Job) {
case cacheObjSubType[`job_get_hammer_time`]: case cacheObjSubType[`job_get_hammer_time`]:
jobGetHammerTime(j) jobGetHammerTime(j)
default: default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID) log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
} }
} else { } else {
log.Printf("JobWorker[%d] : Job %d timed out.\n", id, j.ID64) log.Printf("JobWorker[%d] : Job %d timed out.\n", id, j.ID64)