This commit is contained in:
shoopea 2019-05-30 10:05:43 +08:00
parent a2cf83994e
commit f919abfd3f

6
job.go
View File

@ -102,6 +102,7 @@ func loadCurrentJobs(sid int) ([]Job, error) {
var ( var (
objId int64 objId int64
jobTypeId int32 jobTypeId int32
userID64 int64
status int32 status int32
payload []byte payload []byte
jobs []Job jobs []Job
@ -110,7 +111,7 @@ func loadCurrentJobs(sid int) ([]Job, error) {
_, err := db.Exec("UPDATE obj_job j SET session_id = ?, j.pulled = ?, j.in_work = 1 WHERE j.is_done = 0 AND j.in_work = 0 AND j.schedule <= ? ORDER BY j.priority ASC, j.obj_id ASC LIMIT ?;", sid, time.Now(), time.Now(), SQLJobSliceSize) _, err := db.Exec("UPDATE obj_job j SET session_id = ?, j.pulled = ?, j.in_work = 1 WHERE j.is_done = 0 AND j.in_work = 0 AND j.schedule <= ? ORDER BY j.priority ASC, j.obj_id ASC LIMIT ?;", sid, time.Now(), time.Now(), SQLJobSliceSize)
logOnError(err, "loadCurrentJobs : update intial rows") logOnError(err, "loadCurrentJobs : update intial rows")
stmt, err := db.Prepare("SELECT o.id, o.obj_sub_type_id, j.status, j.payload FROM obj_job j, obj o WHERE j.obj_id = o.id AND j.is_done = 0 AND j.in_work = 1 AND j.session_id = ? ORDER BY j.priority ASC, j.obj_id ASC;") stmt, err := db.Prepare("SELECT o.id, o.obj_sub_type_id, j.status, j.user_id, j.payload FROM obj_job j, obj o WHERE j.obj_id = o.id AND j.is_done = 0 AND j.in_work = 1 AND j.session_id = ? ORDER BY j.priority ASC, j.obj_id ASC;")
logOnError(err, "loadCurrentJobs : prepare select statement") logOnError(err, "loadCurrentJobs : prepare select statement")
rows, err := stmt.Query(sid) rows, err := stmt.Query(sid)
@ -118,12 +119,13 @@ func loadCurrentJobs(sid int) ([]Job, error) {
logOnError(err, "loadCurrentJobs : query select statement") logOnError(err, "loadCurrentJobs : query select statement")
for rows.Next() { for rows.Next() {
err = rows.Scan(&objId, &jobTypeId, &status, &payload) err = rows.Scan(&objId, &jobTypeId, &status, &userID64, &payload)
logOnError(err, "loadCurrentJobs : scan query rows") logOnError(err, "loadCurrentJobs : scan query rows")
job := Job{ job := Job{
ID64: objId, ID64: objId,
JobTypeID: jobTypeId, JobTypeID: jobTypeId,
Status: status, Status: status,
UserID64: userID64,
Payload: payload, Payload: payload,
} }
jobs = append(jobs, job) jobs = append(jobs, job)