Ejemplo n.º 1
0
func (c Clock) Schedule(name string, eventHandler agent.EventHandler) {
	log.Info("registering new cron job: %s", name)
	job := Job{eventHandler}

	jobrunner.Start()
	jobrunner.Schedule(c.Interval, job)
}
Ejemplo n.º 2
0
func CreateJobsRoutes(r martini.Router) {
	jobrunner.Start() // optional: jobrunner.Start(pool int, concurrent int) (10, 1)
	jobrunner.Schedule("@every 5s", ReminderEmails{})
	jobrunner.Schedule("@every 10s", ReminderEmails{})
	entries := jobrunner.Entries()
	fmt.Println(entries[len(entries)-1].ID)
	r.Get("/status", requestJobs)
}
Ejemplo n.º 3
0
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")
}
Ejemplo n.º 4
0
func main() {
	// Load Environment
	err := godotenv.Load()
	if err != nil {
		os.Exit(-1)
	}

	// Logging with Papertrail
	logger := logrus.New()
	paperTrailPort, err := strconv.Atoi(os.Getenv("OAKED_PAPERTRAIL_PORT"))

	if err != nil {
		logger.Fatal("Unable to convert port to int")
		os.Exit(-1)
	}

	hook, err := logrus_papertrail.NewPapertrailHook(
		&logrus_papertrail.Hook{
			Host:     os.Getenv("OAKED_PAPERTRAIL_HOST"),
			Port:     paperTrailPort,
			Appname:  os.Getenv("OAKED_PAPERTRAIL_HOST_NAME"),
			Hostname: os.Getenv("OAKED_PAPERTRAIL_APP_NAME"),
		})

	if err == nil {
		logger.Hooks.Add(hook)
	} else {
		logger.Fatal("Unable to attach Papertrail Hook")
		os.Exit(-1)
	}

	// Main DB for storing all data (MySQL)
	mainDB, err := utils.ConnectDB(
		os.Getenv("OAKED_MAIN_DB_USERNAME"),
		os.Getenv("OAKED_MAIN_DB_PASSWORD"),
		os.Getenv("OAKED_MAIN_DB_IP_ADDR"),
		os.Getenv("OAKED_MAIN_DB_PORT"),
		os.Getenv("OAKED_MAIN_DB"))

	defer mainDB.Close()

	if err != nil {
		logger.Printf("Unable to connect to Main DB (%v)", err)
		os.Exit(-1)
	}
	/*
		// Cache DB w/ Bolt
		cacheDB, err := bolt.Open(
			os.Getenv("THISY_CACHE_DB"),
			0600,
			&bolt.Options{Timeout: 1 * time.Second})

		if err != nil {
			logger.Printf("Unable to connect to Cache DB (%v)", err)
			os.Exit(-1)
		}

		defer cacheDB.Close()

		// Setup the DB Buckets (if not already done)
		err = cacheDB.Update(func(tx *bolt.Tx) error {
			_, err := tx.CreateBucketIfNotExists([]byte(
				os.Getenv("OAKED_CACHE_DB_EMBED_BUCKET")))
			_, err = tx.CreateBucketIfNotExists([]byte(
				os.Getenv("OAKED_CACHE_DB_STORES_BUCKET")))
			return err
		})

		if err != nil {
			logger.Printf("Unable to create cache DB buckets (%v)", err)
			os.Exit(-1)
		}

		// Session DB (for auth)
		sessionStore, err := redistore.NewRediStore(
			10,
			"tcp",
			os.Getenv("OAKED_SESSION_DB_PORT"),
			os.Getenv("OAKED_SESSION_DB_AUTH"),
			[]byte(os.Getenv("OAKED_SESSION_DB_SESSION_BUCKET")))

		if err != nil {
			logger.Printf("Unable to connect to Session DB (%v)", err)
			os.Exit(-1)
		}

		defer sessionStore.Close()

		sessionStore.Options = &sessions.Options{
			Domain:   os.Getenv("THISY_SESSION_DOMAIN"),
			Path:     "/",
			MaxAge:   30 * 24 * 3600,
			Secure:   true,
			HttpOnly: true,
		}
	*/
	// Template Loading

	// Routing & HTTP Server
	mx := mux.NewRouter()
	router.Router(mx,
		&config.Env{
			MainDB: mainDB,
			//	Cache:   cacheDB,
			Log: logger,
			//	Session: sessionStore
		})

	jobrunner.Start()

	http.ListenAndServe(":9001", mx)
}
Ejemplo n.º 5
0
func (s schedule) Start() schedule {
	jobrunner.Start()
	return s
}