Пример #1
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()
}
Пример #2
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()
}
Пример #3
0
// syncTaskJob would do whatever syncing is necessary in the background
func syncTaskJob(j *que.Job) error {
	var synctask sync.SyncTask
	err := json.Unmarshal(j.Args, &synctask)
	if err != nil {
		log.WithField("args", string(j.Args)).Error("Unable to unmarshal job arguments into SyncTask")
		return err
	}

	log.WithField("SyncTask", synctask).Info("Processing Synctask!")

	stvClientImpl := stv.CreateStravaClient(synctask.StravaToken)
	rkClientImpl := rk.CreateRKClient(synctask.RunkeeperToken)
	_, _, err = synctask.Sync(stvClientImpl, rkClientImpl)
	if err != nil {
		log.WithField("args", string(j.Args)).WithField("QueId", j.ID).Error("Error while syncing synctask.")
		return err
	}

	j.Delete()
	j.Done()

	return nil
}