示例#1
0
func startIsmonitor(daemonMode bool) {
	configFile, err := ioutil.ReadFile("config.json")
	if err != nil {
		log.Fatalln(err)
	}

	var config config
	err = json.Unmarshal(configFile, &config)
	if err != nil {
		log.Fatalln(err)
	}

	if daemonMode && config.CronSchedule == nil {
		fmt.Println("Daemon mode but no cron schedule specified. Quitting.")
		os.Exit(1)
	}
	if !daemonMode && config.CronSchedule != nil {
		fmt.Println("Daemon mode not specified but a cron schedule specified. Quitting.")
		os.Exit(1)
	}

	if config.CronSchedule != nil {
		cron := cron.New()
		cron.AddJob(*config.CronSchedule, monitorJob{&config})
		cron.Start()
		defer cron.Stop()
		select {}
	} else {
		runIsmonitor(config)
	}
}
示例#2
0
func (p *Poller) Run() {

	// Setup DocumentType
	if p.config.DocumentType == "" {
		p.config.DocumentType = DefaultDocumentType
	}

	//init the cron schedule
	if p.config.Cron != "" {
		p.cron = p.config.Cron
	} else {
		p.cron = DefaultCron
	}

	cron := cron.New()
	cron.AddFunc(p.config.Cron, func() { p.runOneTime() })
	cron.Start()
}
示例#3
0
func (e *Executor) Run() {

	// Setup DocumentType
	if e.config.DocumentType == "" {
		e.config.DocumentType = DefaultDocumentType
	}

	//init the cron schedule
	if e.config.Cron != "" {
		e.cron = e.config.Cron
	} else {
		e.cron = DefaultCron
	}

	cron := cron.New()
	cron.AddFunc(e.config.Cron, func() { e.runOneTime() })
	cron.Start()
}
var wasWarned = false
var leewayExpired = false
var leewayMutex = new(sync.Mutex)
var suspendCount = 0
var suspendEnabled = false
var manualBlocked = false
var autoCloseCountdown = 0

var plugin *Plugin = &Plugin{
	Init: func(input chan ChromebusRecord, aggregator Aggregator) {
		log.Printf("Started Activity plugin")

		cron := cron.New()
		cron.AddFunc(resetCron, resetLeeway)
		//cron.AddFunc("0 */5 * * * *", resetLeeway) // 3pm every day
		cron.Start()
		initLeeway()
		go monitor()
	},
	Handle: func(w http.ResponseWriter, r *http.Request) {
		log.Printf(r.URL.Path)
		switch r.URL.Path {
		case "/" + string(ActivityTracker) + "/suspend":
			if leewayExpired {
				log.Printf("suspending...")
				leewayMutex.Lock()
				suspendEnabled = true
				suspendCount++
				leewayMutex.Unlock()
			}
		case "/" + string(ActivityTracker) + "/isleewayexpired":