This commit is contained in:
shoopea 2020-01-12 17:32:31 +08:00
parent 748bf5892b
commit f94e710911
2 changed files with 23 additions and 2 deletions

23
job.go
View File

@ -65,6 +65,19 @@ func createJob(jobTypeID64 int64, priority int32, userID64 int64, trigger int64,
return 0, err return 0, err
} }
j := new(Job)
j.ID64 = objId
j.JobTypeID64 = jobTypeID64
j.Trigger = trigger
j.Timeout = time.Unix(maxUnixTimestamp, 0).UTC()
j.UserID64 = userID64
j.Payload = payload
muxObjJob.Lock()
cacheObjJob[objId] = *j
muxObjJob.Unlock()
return objId, nil return objId, nil
} }
@ -99,12 +112,20 @@ func setJobTimeout(jobID64 int64, d time.Duration) error {
} }
defer stmt.Close() defer stmt.Close()
_, err = stmt.Exec(time.Now().UTC().Add(d), jobID64) t := time.Now().UTC().Add(d)
_, err = stmt.Exec(t, jobID64)
logOnError(err, fmt.Sprintf("setJobTimeout, update obj_job(%d)", jobID64)) logOnError(err, fmt.Sprintf("setJobTimeout, update obj_job(%d)", jobID64))
if err != nil { if err != nil {
return err return err
} }
muxObjJob.Lock()
j := cacheObjJob[jobID64]
j.Timeout = t
cacheObjJob[jobID64] = j
muxObjJob.Unlock()
return nil return nil
} }

2
obj.go
View File

@ -1026,7 +1026,7 @@ func loadObjJob() error {
muxObjJob.Lock() muxObjJob.Lock()
cacheObjJob = make(map[int64]Job) cacheObjJob = make(map[int64]Job)
muxObjItem.Unlock() muxObjJob.Unlock()
jobs, err := db.Query(`SELECT o.id, o.obj_sub_type_id, oj.trigger_id, oj.timeout, oj.user_id, oj.payload FROM obj o, obj_job oj WHERE o.id = oj.obj_id;;`) jobs, err := db.Query(`SELECT o.id, o.obj_sub_type_id, oj.trigger_id, oj.timeout, oj.user_id, oj.payload FROM obj o, obj_job oj WHERE o.id = oj.obj_id;;`)
if err != nil { if err != nil {