func InitRabbitMQ() { var err error RabbitConnection, err = amqp.Dial(os.Getenv("RABBITMQ_URI")) logger.PanicfIfError(err, "Error while dialing to RabbitMQ Server, %s", err) RabbitChannel, err = RabbitConnection.Channel() logger.PanicfIfError(err, "Error while creating RabbitMQ Channel, %s", err) err = RabbitChannel.Qos( 1, // prefetch count 0, // prefetch size false, // global ) logger.PanicfIfError(err, "Error while setting Qos paramter for RabbitMQ, %s", err) err = RabbitChannel.ExchangeDeclare( E_METRIC_EXCHANGE, // name "fanout", // type true, // durable false, // auto-deleted false, // internal false, // no-wait nil, // arguments ) logger.PanicfIfError(err, "Failed to declare an exchange, %s", err) declareAndBindQueue(Q_ACCOUNT_NAME) declareAndBindQueue(Q_DISTINCT_NAME) declareAndBindQueue(Q_HOURLY_LOG) logger.Info("Rabbitmq Successfully Initialize") }
func InitCron() { jobrunner.Start() err := jobrunner.Schedule("@every 1h", WorkerHourlyLog{"WorkerHourlyLog"}) logger.PanicfIfError(err, "Error while scheduling Worker HourlyLog, %s", err) err = jobrunner.Schedule("@every 15m", WorkerAccountName{"WorkerAccountName"}) logger.PanicfIfError(err, "Error while scheduling Worker AccountName, %s", err) err = jobrunner.Schedule("@every 15m", WorkerDistinctName{"WorkerDistinctName"}) logger.PanicfIfError(err, "Error while scheduling Worker DistinctName, %s", err) logger.Info("All the workers are Initialize") }
func InitPg() { var err error db, err = gorm.Open("postgres", os.Getenv("PG_URL")) logger.PanicfIfError(err, "Error while connecting to PostgreSQL, %s", err) db.LogMode(false) db.SingularTable(true) logger.Info("PostgreSQL Successfully Initialize") }
func declareAndBindQueue(qName string) { _, err := RabbitChannel.QueueDeclare( qName, // name true, // durable false, // delete when unused false, // exclusive false, // no-wait nil, // arguments ) logger.PanicfIfError(err, "Error while declaring Queue - %s, %s", qName, err) err = RabbitChannel.QueueBind( qName, // queue name "", // routing key E_METRIC_EXCHANGE, // exchange false, nil) logger.PanicfIfError(err, "Failed to bind queue - %s, %s", qName, err) }
// this initializes the db connection func InitMongo() { var err error mongoSession, err = mgo.Dial(os.Getenv("MG_URI")) logger.PanicfIfError(err, "Error while initalizing MongoDB, %s", err) // Reads may not be entirely up-to-date, but they will always see the // history of changes moving forward, the data read will be consistent // across sequential queries in the same session, and modifications made // within the session will be observed in following queries (read-your-writes). // http://godoc.org/labix.org/v2/mgo#Session.SetMode mongoSession.SetMode(mgo.Monotonic, true) logger.Info("MongoDB Successfully Initialize") }
func InitRedis() { var err error conn, err = redis.Dial("tcp", os.Getenv("REDIS_URL")) logger.PanicfIfError(err, "Error while Initializing Redis, %s", err) logger.Info("Redis Successfully Initialize") }