Beispiel #1
0
func (self *Server) SetQueryInterval(seconds int) {
	if seconds < 3 {
		seconds = 60
	}
	if self.Cron != nil {
		go self.Cron.Stop()
	}

	self.QueryIntervalSec = seconds
	self.Schedule = cron.Every(time.Duration(self.QueryIntervalSec) * time.Second)
}
Beispiel #2
0
// Start begins Reaper's schedule
func (r *Reaper) Start() {
	// adding as a job runs r.Run() every interval
	r.Cron.Schedule(cron.Every(config.Notifications.Interval.Duration), r)
	r.Cron.AddFunc("@weekly", GetPrices)
	r.Cron.Start()

	// initial prices download, synchronous
	GetPrices()

	// initial run
	go r.Run()
}
Beispiel #3
0
// Run the given job at a fixed interval.
// The interval provided is the time between the job ending and the job being run again.
// The time that the job takes to run is not included in the interval.
func Every(duration time.Duration, job cron.Job) {
	MainCron.Schedule(cron.Every(duration), New(job))
}
Beispiel #4
0
func main() {
	flag.Usage = usage
	flag.Parse()
	args := flag.Args()

	if ver {
		fmt.Println("Version:", version)
		os.Exit(0)
	}
	if hlp {
		usage()
	}

	runMode := run_mode_default
	if cronT != default_cron {
		runMode = run_mode_cron
	} else if timeD != default_time {
		runMode = run_mode_time
	} else if loop != default_loop {
		runMode = run_mode_loop
	} else {
		fmt.Println("do not set -loop, -time or -cron. ant wiil run with default mode(loop once).")
	}
	sigCh := make(chan os.Signal, 1)
	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGKILL)
	defer close(sigCh)
	c := cron.New()

	w, err := filter(args)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}

	if runMode == run_mode_cron {
		// crontab
		schedule, err := cron.Parse(cronT)
		if err != nil {
			fmt.Println(err)
			os.Exit(0)
		}

		c.Schedule(schedule, &moveJob{w})
		c.Start()
		defer c.Stop()
	} else if runMode == run_mode_time {
		// time
		schedule := cron.Every(timeD)
		c := cron.New()
		c.Schedule(schedule, &moveJob{w})
		c.Start()
		defer c.Stop()
	} else if runMode == run_mode_loop {
		// loop
		job := &moveJob{w}
		for i := 0; i < loop; i++ {
			job.Run()
			time.Sleep(5 * time.Second)
		}
		os.Exit(0)
	} else if runMode == run_mode_default {
		// default
		job := &moveJob{w}
		job.Run()
		os.Exit(0)
	} else {
		fmt.Printf("run mode [%d] unknown.\n", runMode)
		os.Exit(0)
	}

	sig := <-sigCh
	fmt.Println("Got signal:", sig)
}