当前位置: 首页>>代码示例>>Golang>>正文


Golang Job.Id方法代码示例

本文整理汇总了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方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Save

func (l LevelDBDriver) Save(job *driver.Job) (err error) {
	defer l.RWLocker.Unlock()
	l.RWLocker.Lock()
	batch := new(leveldb.Batch)
	var isNew = true
	if job.Id > 0 {
		isNew = false
	} else {
		last_id, e := l.db.Get([]byte(PRE_SEQUENCE+"JOB"), nil)
		if e != nil || last_id == nil {
			job.Id = 1
		} else {
			id, _ := strconv.ParseInt(string(last_id), 10, 64)
			job.Id = id + 1
		}
	}
	var strId = strconv.FormatInt(job.Id, 10)
	if isNew {
		batch.Put([]byte(PRE_SEQUENCE+"JOB"), []byte(strId))
		batch.Put([]byte(PRE_JOB_FUNC+job.Func+":"+job.Name), []byte(strId))
	} else {
		old, e := l.get(job.Id)
		if e != nil || old.Id == 0 {
			err = errors.New(fmt.Sprintf("Update Job %d fail, the old job is not exists.", job.Id))
			return
		}
		l.cache.Remove(PRE_JOB + strId)
		if old.Name != job.Name {
			batch.Delete([]byte(PRE_JOB_FUNC + job.Func + ":" + old.Name))
			batch.Put([]byte(PRE_JOB_FUNC+job.Func+":"+job.Name), []byte(strId))
		}
	}
	batch.Put([]byte(PRE_JOB+strId), job.Bytes())
	err = l.db.Write(batch, nil)
	return
}
开发者ID:4honor,项目名称:periodic,代码行数:36,代码来源:leveldb.go

示例2: HandleSubmitJob

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
}
开发者ID:4honor,项目名称:periodic,代码行数:41,代码来源:client.go


注:本文中的github.com/Lupino/periodic/driver.Job.Id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。