コード例 #1
0
ファイル: sched.go プロジェクト: 4honor/periodic
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
}
コード例 #2
0
ファイル: sched.go プロジェクト: monsterwof/periodic
func (sched *Sched) submitJob(item 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 !item.w.alive {
		return false
	}
	if err := item.w.handleJobAssign(item.msgID, job); err != nil {
		item.w.alive = false
		return false
	}
	now := time.Now()
	current := int64(now.Unix())
	job.SetProc()
	job.RunAt = current
	sched.driver.Save(&job)
	sched.incrStatProc(job)
	sched.pushRevertPQ(job)
	sched.notifyRevertTimer()
	sched.procQueue[job.ID] = job
	sched.grabQueue.remove(item)
	return true
}