Ejemplo n.º 1
0
func main() {
	cfg.Init()
	defer cfg.Finalize()

	n := 0
	for _, e := range cfg.Config.Engines {
		for i := 0; i < e.Workers; i++ {
			sigchan = append(sigchan, workerSentry(e, i))
			n++
		}
	}
	registerSignals(n)
	wg.Add(n)
	glog.Infoln("Waiting To Finish")
	wg.Wait()
	glog.Infoln("Gracefully terminated Program")
}
Ejemplo n.º 2
0
func main() {
	cfg.Init()
	defer cfg.Finalize()

	for _, e := range cfg.Config.Engines {
		registerQueue(http.DefaultServeMux, e)
		engineNames = append(engineNames, e.Name) // Add to list of engines
	}

	httpHandleStripped("/files/", http.FileServer(http.Dir(*store)))
	httpHandleStripped("/console/", http.FileServer(http.Dir("./console")))

	httpHandleStripped("/result/", http.HandlerFunc(handleResult))
	httpHandleStripped(link, http.HandlerFunc(handleLink))
	httpHandleStripped("/monitor/jobs/paginate", http.HandlerFunc(handleGetPagination))
	httpHandleStripped("/monitor/jobs/", http.HandlerFunc(handleGetJobs))
	httpHandleStripped("/monitor/queues", http.HandlerFunc(handleQueues))

	glog.Infoln("Listening on", *addr)
	err := http.ListenAndServe(*addr, nil)
	if err != nil {
		glog.Errorln("Couldn't listen", err)
	}
}
Ejemplo n.º 3
0
func main() {
	cfg.Init()
	defer cfg.Finalize()

	engine = NewEngineContainerWrap(*engineType, *workerIndex)
	// TODO: pull image before reading from the queue
	conn, err := cfg.NewRabbitmqConn()
	if err != nil {
		glog.Errorln("Couldn't connect to rabbitmq", err)
		return
	}
	defer conn.Close()

	ch, err := conn.Channel()
	if err != nil {
		glog.Errorln("Couldn't open rabbitmq channel", err)
		return
	}
	defer ch.Close()

	q, err := ch.QueueDeclare(
		*engineType, // name
		true,        // durable
		false,       // delete when unused
		false,       // exclusive
		false,       // no-wait
		nil,         // arguments
	)
	if err != nil {
		glog.Errorln("Couldn't open rabbitmq queue", *engineType, err)
		return
	}

	// make sure we fetch one at a time
	err = ch.Qos(
		1,     // prefetch count
		0,     // prefetch size
		false, // global
	)
	if err != nil {
		glog.Errorln("Failed to set QoS to RmQ channel")
		return
	}

	consumer := fmt.Sprintf("pid-%d", os.Getpid())
	msgs, err := ch.Consume(
		q.Name,   // queue
		consumer, // consumer string
		false,    // auto-ack
		false,    // exclusive
		false,    // no-local
		false,    // no-wait
		nil,      // args
	)
	if err != nil {
		glog.Errorln("Failed to start RmQ consumption loop")
		return
	}

	for i := 0; i < *joblimit || *joblimit == 0; i++ {
		if d, gotMsg := <-msgs; gotMsg {
			work(d)
		} else {
			glog.Warningln("Message channel closed. Exiting.")
			break
		}
	}
	ch.Cancel(consumer, true)
}