Пример #1
0
func GetProject(project string) (p Project) {
	p, ok := projects[project]
	if !ok {
		p = Project{
			Workers: make(map[string]Worker),
		}
		p.Jobs = xsync.NewWQueue(&p.lock)
		projects[project] = p
	}
	return
}
Пример #2
0
package main

import (
	"github.com/skelterjohn/alum.inum/messages"
	"github.com/skelterjohn/alum.inum/xsync"
	"log"
)

// all jobs go through this queue
var jobQueue = xsync.NewWQueue(nil)

// here are jobs for which we are awaiting a worker
var backLog = xsync.NewWQueue(nil)

// signals down these channels terminate the corresponding workLoops
var workLoopTerminators = make(map[string]chan<- chan bool)

// tracks workers are active
var workStatus = make(map[string]bool)

var workCond = xsync.NewIntCond(nil)

/*
see how many workers there are, and how many are busy
*/
func workerStatus() (active, total int) {
	workCond.Lock()
	total = len(workStatus)
	active = total - workCond.Value
	workCond.Unlock()
	return
Пример #3
0
package main

import (
	"github.com/skelterjohn/alum.inum/messages"
	"github.com/skelterjohn/alum.inum/xsync"
	"log"
	"net"
)

var stalledJobs = xsync.NewWQueue(nil)

func flushDelegates() {
	jobs := stalledJobs.PopAll()
	for _, j := range jobs {
		log.Printf("requeueing %v", j)
		jobQueue.Push <- j
		jobClaims.setJobStatus(j.(Job).JobHeader, messages.JobQueued)
	}
	select {
	case j := <-stalledJobs.Pop:
		log.Printf("requeueing %v", j)
		jobQueue.Push <- j
		jobClaims.setJobStatus(j.(Job).JobHeader, messages.JobQueued)
	default:
	}
}

func delegateJob(j Job) {
	log.Println("too busy for", j)

	var conn *net.TCPConn