Example #1
0
func main() {
	var configFiles string
	flag.StringVar(&configFiles, "config", "common.conf", "configuration files (comma separated)")
	////
	flag.Parse() // needed for glog

	config.ParseConfigFiles(configFiles, &ConfigSections)

	// see here for the terms http://api.zeromq.org/3-2:zmq-proxy
	go RunStreamerProxy(ConfigSections.Common.ZmqConfirmEmailPushPort, ConfigSections.Common.ZmqConfirmEmailPullPort)
	go RunStreamerProxy(ConfigSections.Common.ZmqResetEmailPushPort, ConfigSections.Common.ZmqResetEmailPullPort)
	go RunStreamerProxy(ConfigSections.Common.ZmqProjectToBeProcessedPushPort, ConfigSections.Common.ZmqProjectToBeProcessedPullPort)

	go RunForwarderProxy(ConfigSections.Common.ZmqGeneralPubPort, ConfigSections.Common.ZmqGeneralSubPort)

	select {}
}
Example #2
0
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// initialize and start workers in seperate go routines
func main() {
	hostname, err := os.Hostname()
	if err != nil {
		glog.Error("Failed to get hostname")
		return
	}

	var configFiles string
	flag.StringVar(&configFiles, "config", "backend.conf,common.conf", "configuration files (comma separated)")
	////
	flag.Parse() // needed for glog
	glog.Info("back end worker started. Hostname =  ", hostname)

	config.ParseConfigFiles(configFiles, &ConfigSections)
	glog.V(1).Infof("Config information %+v", ConfigSections)

	backend_utils.ConfigSections = &ConfigSections
	/////

	// database connections
	glog.V(0).Info("starting mongo db session")
	mgoSession, err = mgo.Dial(ConfigSections.Common.MongoDBIp)
	if err != nil {
		panic(err)
	}
	defer mgoSession.Close()
	mgoSession.SetSocketTimeout(1 * time.Hour) //
	mgoSession.SetMode(mgo.Strong, true)

	initializeDbCollections()
	// go func () { // goroutine to periodically ping db and reconnect if necessary
	// 	for {
	// 		time.Sleep (1*time.Second)

	// 		select {

	// 			default:
	// 				err := mgoSession.Ping()
	// 				if err!=nil {
	// 					glog.V(1).Info ("Database ping failed. reconnect")

	// 					for { // keep trying to connect
	// 						mgoSession, err = mgo.Dial(ConfigSections.Common.MongoDBIp)

	// 						if err==nil { // connect ok
	// 							mgoSession.SetMode(mgo.Strong, true)
	// 							mgoSession.SetSocketTimeout(1 * time.Hour) //
	// 							initializeDbCollections()

	// 							break
	// 						}
	// 						// keep trying to connect again
	// 						glog.V(1).Info ("Reconnect DB failed. try again")

	// 						time.Sleep (1*time.Second)
	// 					}

	// 				}

	// 		}

	// 	}
	// } ()

	////////////
	//
	sendConfirmEmailQueueReceiver, _ := zmq.NewSocket(zmq.PULL)
	defer sendConfirmEmailQueueReceiver.Close()

	emailQueueConnectStr := "tcp://" + ConfigSections.Common.ZmqProxyHost + ":" + ConfigSections.Common.ZmqConfirmEmailPullPort
	glog.V(1).Info("Email queue zmq :" + emailQueueConnectStr)
	sendConfirmEmailQueueReceiver.Connect(emailQueueConnectStr)

	/////
	sendResetEmailQueueReceiver, _ := zmq.NewSocket(zmq.PULL)
	defer sendResetEmailQueueReceiver.Close()

	resetQueueConnectStr := "tcp://" + ConfigSections.Common.ZmqProxyHost + ":" + ConfigSections.Common.ZmqResetEmailPullPort
	glog.V(1).Info("Email queue zmq :" + resetQueueConnectStr)
	sendResetEmailQueueReceiver.Connect(resetQueueConnectStr)

	////
	projectToBeProcessedQueueReceiver, _ := zmq.NewSocket(zmq.PULL)
	defer projectToBeProcessedQueueReceiver.Close()

	projectQueueConnectStr := "tcp://" + ConfigSections.Common.ZmqProxyHost + ":" + ConfigSections.Common.ZmqProjectToBeProcessedPullPort
	glog.V(1).Info("Project queue zmq :" + projectQueueConnectStr)
	projectToBeProcessedQueueReceiver.Connect(projectQueueConnectStr)

	// start all go routines to process work queues
	///////////////

	go backend_utils.SendConfirmEmailQueueHandler(sendConfirmEmailQueueReceiver)
	go backend_utils.SendResetEmailQueueHandler(sendResetEmailQueueReceiver)
	go processProjectQueueHandler(projectToBeProcessedQueueReceiver)

	// the clean up worker - go and clean deleted projects
	go cleanupDeletedProjects()

	// realtime profiling for DEBUGGING
	go func() {
		http.ListenAndServe(":6060", nil)
	}()
	select {}
}