本文整理汇总了Golang中github.com/Lupino/periodic/driver.Job.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang Job.ID方法的具体用法?Golang Job.ID怎么用?Golang Job.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Lupino/periodic/driver.Job
的用法示例。
在下文中一共展示了Job.ID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleSubmitJob
func (c *httpClient) handleSubmitJob(req *http.Request) {
var job driver.Job
var e error
var sched = c.sched
defer sched.jobLocker.Unlock()
sched.jobLocker.Lock()
url := req.URL.String()
funcName := url[1:]
if funcName == "" {
funcName = req.FormValue("func")
}
job.Name = req.FormValue("name")
job.Func = funcName
job.Args = req.FormValue("args")
job.Timeout, _ = strconv.ParseInt(req.FormValue("timeout"), 10, 64)
job.SchedAt, _ = strconv.ParseInt(req.FormValue("sched_at"), 10, 64)
if job.Name == "" || job.Func == "" {
c.sendErrResponse(errors.New("job name or func is required"))
return
}
isNew := true
changed := false
job.SetReady()
oldJob, e := sched.driver.GetOne(job.Func, job.Name)
if e == nil && oldJob.ID > 0 {
job.ID = oldJob.ID
if job.IsProc() {
sched.decrStatProc(oldJob)
sched.removeRevertPQ(job)
changed = true
}
isNew = false
}
e = sched.driver.Save(&job)
if e != nil {
c.sendErrResponse(e)
return
}
if isNew {
sched.incrStatJob(job)
}
if isNew || changed {
sched.pushJobPQ(job)
}
sched.notifyJobTimer()
c.sendResponse("200 OK", []byte("{\"msg\": \""+protocol.SUCCESS.String()+"\"}"))
return
}
示例2: Save
// Save job. when job is exists update it, other create one.
func (l Driver) Save(job *driver.Job, force ...bool) (err error) {
defer l.RWLocker.Unlock()
l.RWLocker.Lock()
batch := new(leveldb.Batch)
var isNew = true
if job.ID > 0 {
isNew = false
} else {
lastID, e := l.db.Get([]byte(PRESEQUENCE+"JOB"), nil)
if e != nil || lastID == nil {
job.ID = 1
} else {
id, _ := strconv.ParseInt(string(lastID), 10, 64)
job.ID = id + 1
}
}
var strID = strconv.FormatInt(job.ID, 10)
if isNew {
batch.Put([]byte(PRESEQUENCE+"JOB"), []byte(strID))
batch.Put([]byte(PREFUNC+job.Func+":"+job.Name), []byte(strID))
} else if len(force) == 0 || !force[0] {
old, e := l.get(job.ID)
if e != nil || old.ID == 0 {
err = fmt.Errorf("Update Job %d fail, the old job is not exists.", job.ID)
return
}
l.cache.Remove(PREJOB + strID)
if old.Name != job.Name {
batch.Delete([]byte(PREFUNC + job.Func + ":" + old.Name))
batch.Put([]byte(PREFUNC+job.Func+":"+job.Name), []byte(strID))
}
}
batch.Put([]byte(PREJOB+strID), job.Bytes())
err = l.db.Write(batch, nil)
return
}
示例3: handleSubmitJob
func (c *client) handleSubmitJob(msgID []byte, payload []byte) (err error) {
var job driver.Job
var e error
var conn = c.conn
var sched = c.sched
defer sched.jobLocker.Unlock()
sched.jobLocker.Lock()
job, e = driver.NewJob(payload)
if e != nil {
err = conn.Send([]byte(e.Error()))
return
}
isNew := true
changed := false
job.SetReady()
oldJob, e := sched.driver.GetOne(job.Func, job.Name)
if e == nil && oldJob.ID > 0 {
job.ID = oldJob.ID
if oldJob.IsProc() {
sched.decrStatProc(oldJob)
sched.removeRevertPQ(job)
changed = true
}
isNew = false
}
e = sched.driver.Save(&job)
if e != nil {
err = conn.Send([]byte(e.Error()))
return
}
if isNew {
sched.incrStatJob(job)
}
if isNew || changed {
sched.pushJobPQ(job)
}
sched.notifyJobTimer()
err = c.handleCommand(msgID, protocol.SUCCESS)
return
}