update jobs

This commit is contained in:
shoopea 2020-01-21 14:18:23 +08:00
parent 6c2b48620a
commit 0e4ca45b80

27
job.go
View File

@ -23,12 +23,23 @@ import (
)
func createJob(jobTypeID64 int64, priority int32, userID64 int64, trigger int64, schedule time.Time, payload []byte) (int64, error) {
var zb bytes.Buffer
zw := zlib.NewWriter(&zb)
zw.Write(payload)
zw.Close()
zpayload := zb.Bytes()
var (
zb bytes.Buffer
zpayload []byte
zipped int
)
if len(payload) > 10000 {
zw := zlib.NewWriter(&zb)
zw.Write(payload)
zw.Close()
zpayload = zb.Bytes()
zipped = 1
} else {
zpayload = payload
zipped = 0
}
if len(zpayload) > 20000 {
return 0, errors.New("payload too long")
@ -55,15 +66,15 @@ func createJob(jobTypeID64 int64, priority int32, userID64 int64, trigger int64,
return 0, err
}
stmt, err = db.Prepare(`INSERT INTO obj_job (obj_id, priority, user_id, trigger_id, seq_nr, schedule, is_done, in_work, inserted, timeout, pulled, started, ended, payload)
VALUES (?, ?, ?, ?, NULL, ?, 0, 0, ?, ?, NULL, NULL, NULL, ?);`)
stmt, err = db.Prepare(`INSERT INTO obj_job (obj_id, priority, user_id, trigger_id, seq_nr, schedule, is_done, in_work, inserted, timeout, pulled, started, ended, zipped, payload)
VALUES (?, ?, ?, ?, NULL, ?, 0, 0, ?, ?, NULL, NULL, NULL, ?, ?);`)
logOnError(err, "createJob : prepare insert obj_job")
if err != nil {
return 0, err
}
defer stmt.Close()
_, err = stmt.Exec(objId, priority, userID64, trigger, schedule.UTC(), time.Now().UTC(), time.Unix(maxUnixTimestamp, 0).UTC(), zpayload)
_, err = stmt.Exec(objId, priority, userID64, trigger, schedule.UTC(), time.Now().UTC(), time.Unix(maxUnixTimestamp, 0).UTC(), zipped, zpayload)
logOnError(err, "createJob : insert obj_job")
if err != nil {
return 0, err