コード例 #1
0
ファイル: build.go プロジェクト: zenlinTechnofreak/generator
// handle job when has a free docker machine and an unhandle job
func handleJob() {
	for {
		worker := <-freeWorkerList
		models.MoveFromListByValue("FreeWorkerList", worker, 0)
		job := <-unhandleJobList
		jobStr, err := json.Marshal(job)
		if err != nil {
			log.Println("[ErrorInfo]", err)
		}

		models.MoveFromListByValue("DockerJobList", string(jobStr), 0)
		busyWorkerList = append(busyWorkerList, worker)
		models.PushMsgToList("BusyWorkerList", worker)
		var in io.Reader
		if job.Mode == "dockerfile" {
			in = tarDockerFile(job.Context)
		} else if job.Mode == "archive" {
			in = readArchive(job.Context)
		} else {
			log.Printf("[ErrorInfo] : %v\n", errors.New("Wrong mode, required mode exactly."))
		}

		job.ImageConfig.Context = in

		go BuildDockerImageStartByHTTPReq(worker, job)
	}
}
コード例 #2
0
ファイル: build.go プロジェクト: pombredanne/generator-1
// handle job when has a free docker machine and an unhandle job
func handleJob() {
	for {
		worker := <-freeWorkerList
		models.MoveFromListByValue("FreeWorkerList", worker, 0)
		job := <-unhandleJobList
		jobStr, err := json.Marshal(job)
		if err != nil {
			log.Println("[ErrorInfo]", err)
		}

		models.MoveFromListByValue("DockerJobList", string(jobStr), 0)
		busyWorkerList = append(busyWorkerList, worker)
		models.PushMsgToList("BusyWorkerList", worker)

		go BuildDockerImageStartByHTTPReq(worker, job.Name, tarDockerFile(job.DockerFile), job.Tag)
	}
}
コード例 #3
0
ファイル: build.go プロジェクト: pombredanne/generator-1
// add a docker machine to worker list
func finishJob(addr string) {

	models.MoveFromListByValue("BusyWorkerList", addr, 0)

	// add worker to freeWorkerList
	freeWorkerList <- addr

	// cycle busyWorkerList to remove this worker
	temp := make(chan string, 65535)

	for _, v := range busyWorkerList {
		if v != addr {
			temp <- v
		}
	}

	freeWorkerList = temp
}