func (sched *Sched) SubmitJob(grabItem GrabItem, job driver.Job) bool { defer sched.JobLocker.Unlock() sched.JobLocker.Lock() if job.Name == "" { sched.driver.Delete(job.Id) return true } if _, ok := sched.procQueue[job.Id]; ok { return true } if !grabItem.w.alive { return false } if err := grabItem.w.HandleDo(grabItem.msgId, job); err != nil { grabItem.w.alive = false return false } now := time.Now() current := int64(now.Unix()) job.Status = driver.JOB_STATUS_PROC job.RunAt = current sched.driver.Save(&job) sched.IncrStatProc(job) sched.pushRevertPQ(job) sched.NotifyRevertTimer() sched.procQueue[job.Id] = job sched.grabQueue.Remove(grabItem) return true }
func (client *Client) HandleSubmitJob(msgId int64, payload []byte) (err error) { var job driver.Job var e error var conn = client.conn var sched = client.sched defer sched.JobLocker.Unlock() sched.JobLocker.Lock() job, e = driver.NewJob(payload) if e != nil { err = conn.Send([]byte(e.Error())) return } is_new := true changed := false job.Status = driver.JOB_STATUS_READY oldJob, e := sched.driver.GetOne(job.Func, job.Name) if e == nil && oldJob.Id > 0 { job.Id = oldJob.Id if oldJob.Status == driver.JOB_STATUS_PROC { sched.DecrStatProc(oldJob) sched.removeRevertPQ(job) changed = true } is_new = false } e = sched.driver.Save(&job) if e != nil { err = conn.Send([]byte(e.Error())) return } if is_new { sched.IncrStatJob(job) } if is_new || changed { sched.pushJobPQ(job) } sched.NotifyJobTimer() err = client.HandleCommand(msgId, protocol.SUCCESS) return }