示例#1
0
func InitHandlerList() {
	freeWorkerList = make(chan string, 65535)
	unhandleJobList = make(chan *Job, 65535)

	// get all worker list
	workers, err := models.GetMsgFromList("DockerList", int64(0), int64(-1))
	if err != nil {
		log.Println("[ErrorInfo]", err.Error())
	}

	for _, v := range workers {
		addWorker(v)
	}

	// read unhandleJobList from redis
	jobs, err := models.GetMsgFromList("DockerJobList", int64(0), int64(-1))
	if err != nil {
		log.Println("[ErrorInfo]", err.Error())
	}

	for _, v := range jobs {
		temp := new(Job)
		err := json.Unmarshal([]byte(v), temp)
		if err != nil {
			log.Println("[ErrorInfo]", err.Error())
		}
		unhandleJobList <- temp
	}

	go handleJob()
}
示例#2
0
func getAllOldLogById(id string, WSWriter chan []uint8) {
	strs, err := models.GetMsgFromList("buildLog:"+id, int64(0), int64(-1))
	if err != nil {
		log.Println("[ErrorInfo]", err)
	}

	for _, str := range strs {
		WSWriter <- []uint8(str)
	}
}
示例#3
0
func PushLog(ws *websocket.Conn, id string) {

	defer ws.Close()

	var WSWriter = make(chan []uint8, 1024)
	isWaitJob := false
	waittingJobs, err := models.GetMsgFromList("DockerJobList", 0, -1)
	if err != nil {
		log.Println("[ErrorInfo]", err)
	}
	for _, v := range waittingJobs {
		if strings.Index(v, id) != -1 {
			msg := "waitting build ..."
			if err := ws.WriteMessage(websocket.TextMessage, []byte(msg)); err != nil {
				log.Println("[ErrorInfo]", err.Error())
				return
			}
			isWaitJob = true
		}
	}
	if isWaitJob {
		return
	}
	len, err := models.GetListLength("buildLog:" + id)
	if err != nil {
		log.Println("[ErrorInfo]", err)
	}
	if len == int64(0) {
		msg := "invalid id ..."
		if err := ws.WriteMessage(websocket.TextMessage, []byte(msg)); err != nil {
			log.Println("[ErrorInfo]", err.Error())
		}
		return
	}
	// push data in channel to socket
	go PushMsg(ws, WSWriter)
	// get build log history and push to channel
	getAllOldLogById(id, WSWriter)
	// get new build log and push to channel
	go startSubscribe(id, WSWriter)

	<-endChan
}
示例#4
0
func httpBuildLog(ctx *macaron.Context) {

	logId := ctx.Params("id")
	count := ctx.QueryInt64("count")

	var str []uint8
	strs, err := models.GetMsgFromList("buildLog:"+logId, count, count+1)
	if err != nil {
		log.Println("[ErrorInfo]", err.Error())
		str = []uint8("error in server")
	}

	if len(strs) > 0 {
		str = []uint8(strs[0])
	} else {
		str = []uint8("")
	}

	ctx.Resp.Write(str)
}