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


Golang Job.Bytes方法代码示例

本文整理汇总了Golang中github.com/Lupino/periodic/driver.Job.Bytes方法的典型用法代码示例。如果您正苦于以下问题:Golang Job.Bytes方法的具体用法?Golang Job.Bytes怎么用?Golang Job.Bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/Lupino/periodic/driver.Job的用法示例。


在下文中一共展示了Job.Bytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SubmitJob

func SubmitJob(entryPoint string, job driver.Job) {
	parts := strings.SplitN(entryPoint, "://", 2)
	c, err := net.Dial(parts[0], parts[1])
	if err != nil {
		log.Fatal(err)
	}
	conn := protocol.NewClientConn(c)
	defer conn.Close()
	err = conn.Send(protocol.TYPE_CLIENT.Bytes())
	if err != nil {
		log.Fatal(err)
	}
	var msgId = []byte("100")
	buf := bytes.NewBuffer(nil)
	buf.Write(msgId)
	buf.Write(protocol.NULL_CHAR)
	buf.WriteByte(byte(protocol.SUBMIT_JOB))
	buf.Write(protocol.NULL_CHAR)
	buf.Write(job.Bytes())
	err = conn.Send(buf.Bytes())
	if err != nil {
		log.Fatal(err)
	}
	payload, err := conn.Receive()
	if err != nil {
		log.Fatal(err)
	}
	_, cmd, _ := protocol.ParseCommand(payload)
	fmt.Printf("%s\n", cmd.String())
}
开发者ID:banyue,项目名称:periodic,代码行数:30,代码来源:submit.go

示例2: HandleDo

func (worker *Worker) HandleDo(msgId int64, job driver.Job) (err error) {
	defer worker.locker.Unlock()
	worker.locker.Lock()
	worker.jobQueue[job.Id] = job
	buf := bytes.NewBuffer(nil)
	buf.WriteString(strconv.FormatInt(msgId, 10))
	buf.Write(protocol.NULL_CHAR)
	buf.WriteString(strconv.FormatInt(job.Id, 10))
	buf.Write(protocol.NULL_CHAR)
	buf.Write(job.Bytes())
	err = worker.conn.Send(buf.Bytes())
	return
}
开发者ID:4honor,项目名称:periodic,代码行数:13,代码来源:worker.go

示例3: handleJobAssign

func (w *worker) handleJobAssign(msgId []byte, job driver.Job) (err error) {
	defer w.locker.Unlock()
	w.locker.Lock()
	w.jobQueue[job.Id] = job
	buf := bytes.NewBuffer(nil)
	buf.Write(msgId)
	buf.Write(protocol.NULL_CHAR)
	buf.Write(protocol.JOB_ASSIGN.Bytes())
	buf.Write(protocol.NULL_CHAR)
	buf.WriteString(strconv.FormatInt(job.Id, 10))
	buf.Write(protocol.NULL_CHAR)
	buf.Write(job.Bytes())
	err = w.conn.Send(buf.Bytes())
	return
}
开发者ID:banyue,项目名称:periodic,代码行数:15,代码来源:worker.go

示例4: Save

func (r RedisDriver) Save(job *driver.Job) (err error) {
	defer r.RWLocker.Unlock()
	r.RWLocker.Lock()
	var key string
	var prefix = REDIS_PREFIX + job.Func + ":"
	var conn = r.pool.Get()
	defer conn.Close()
	if job.Id > 0 {
		old, e := r.get(job.Id)
		key = REDIS_PREFIX + strconv.FormatInt(job.Id, 10)
		if e != nil || old.Id < 1 {
			err = errors.New(fmt.Sprintf("Update Job %d fail, the old job is not exists.", job.Id))
			return
		}
		r.cache.Remove(key)
		if old.Name != job.Name {
			if _, e := conn.Do("ZERM", prefix+"name", old.Name); e != nil {
				log.Printf("Error: ZREM %s %s failed\n", prefix+"name", old.Name)
			}
		}
	} else {
		job.Id, err = redis.Int64(conn.Do("INCRBY", REDIS_PREFIX+"sequence", 1))
		if err != nil {
			return
		}
	}
	idx, _ := redis.Int64(conn.Do("ZSCORE", prefix+"name", job.Name))
	if idx > 0 && idx != job.Id {
		err = errors.New("Duplicate Job name: " + job.Name)
		return
	}
	key = REDIS_PREFIX + strconv.FormatInt(job.Id, 10)
	_, err = conn.Do("SET", key, job.Bytes())
	if err == nil {
		if _, e := conn.Do("ZADD", prefix+"name", job.Id, job.Name); e != nil {
			log.Printf("Error: ZADD %s %d %s fail\n", prefix+"name", job.Id, job.Name)
		}
		if _, e := conn.Do("ZADD", REDIS_PREFIX+"ID", job.Id, strconv.FormatInt(job.Id, 10)); e != nil {
			log.Printf("Error: ZADD %s %d %d fail\n", REDIS_PREFIX+"ID", job.Id, job.Id)
		}
	}
	return
}
开发者ID:4honor,项目名称:periodic,代码行数:43,代码来源:redis.go

示例5: 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
}
开发者ID:monsterwof,项目名称:periodic,代码行数:37,代码来源:leveldb.go

示例6: 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


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