From f94e7109114c46f4d575ddd30fae70e8f641a6e7 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sun, 12 Jan 2020 17:32:31 +0800 Subject: [PATCH] test --- job.go | 23 ++++++++++++++++++++++- obj.go | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/job.go b/job.go index 7d5fe27..cfde274 100644 --- a/job.go +++ b/job.go @@ -65,6 +65,19 @@ func createJob(jobTypeID64 int64, priority int32, userID64 int64, trigger int64, 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 } @@ -99,12 +112,20 @@ func setJobTimeout(jobID64 int64, d time.Duration) error { } 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)) if err != nil { return err } + muxObjJob.Lock() + j := cacheObjJob[jobID64] + j.Timeout = t + cacheObjJob[jobID64] = j + muxObjJob.Unlock() + return nil } diff --git a/obj.go b/obj.go index 9ff1c8e..76ff814 100644 --- a/obj.go +++ b/obj.go @@ -1026,7 +1026,7 @@ func loadObjJob() error { muxObjJob.Lock() 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;;`) if err != nil {