Пример #1
0
func main() {
	//Load config vars
	var err error
	DbConnectionString = os.Getenv("CLEARDB_DATABASE_URL")
	dbURL := os.Getenv("DATABASE_URL")

	log.Printf("Starting SyncMySport-trigger with config: MysqlDBString: %s, PostgresDBString: %s",
		DbConnectionString, dbURL)

	success := false
	i := 0
	for i < 10 && !success {
		pgxpool, qc, err = shared.Setup(dbURL)
		if err != nil {
			if i == 4 {
				log.WithField("DATABASE_URL", dbURL).Fatal("Unable to setup queue / database")
			} else {
				log.Print("Waiting 1 second for retry. I = %d", i)
				time.Sleep(1000 * time.Millisecond)
				i++
			}
		} else {
			success = true
		}
	}

	defer pgxpool.Close()
	startSync()
}
Пример #2
0
func main() {
	log.Print("Starting worker")

	var err error
	dbURL := os.Getenv("DATABASE_URL")
	pgxpool, qc, err = shared.Setup(dbURL)
	if err != nil {
		log.WithField("DATABASE_URL", dbURL).Fatal("Errors setting up the queue / database: ", err)
	}
	defer pgxpool.Close()

	wm := que.WorkMap{
		shared.SyncTaskJob: syncTaskJob,
	}

	// 2 worker go routines
	// LIMITED to 1 per worker.. otherwise we overload Runkeeper
	// and I guess create activties twice.
	workers := que.NewWorkerPool(qc, wm, 1)

	// Catch signal so we can shutdown gracefully
	sigCh := make(chan os.Signal)
	signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT)

	go workers.Start()

	// Wait for a signal
	sig := <-sigCh
	log.WithField("signal", sig).Info("Signal received. Shutting down.")

	workers.Shutdown()
}