コード例 #1
0
ファイル: main.go プロジェクト: fwip/himawari
func main() {
	flag.Parse()

	// Get the latest timestamp.
	t, err := download.Latest()
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("The latest image is at %s.", t)

	// Run the first time.
	if err := run(t); err != nil {
		log.Fatalln(err)
	}

	// Run this baby repeatedly.
	if every > 0 {
		ticker := time.NewTicker(time.Duration(every) * time.Second)
		for {
			// Get the latest timestamp for the second time.
			newt, err := download.Latest()
			if err != nil {
				log.Println(err)
				continue // Restart the download.
			}

			if !newt.Equal(*t) {
				t = newt
				log.Printf("The latest image is at %s.", newt)
				if err := run(t); err != nil {
					log.Print(err)
				}
			}

			// Wait until the next tick.
			<-ticker.C
		}
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: leobcn/himawari
func main() {
	flag.Parse()

	// Start off with a dummy time.
	t := time.Unix(0, 0)

	// Run the program.
	for ticker := time.NewTicker(time.Duration(every) * time.Second); ; <-ticker.C {
		// Get the latest timestamp.
		newt, err := download.Latest()
		if err != nil {
			continue // The update server threw an error. Try later.
		}
		log.Printf("The latest image is at %s.\n", newt)

		// Skip if the latest time hasn't changed.
		if newt.Equal(t) {
			log.Println("The image has not changed. Waiting...")
			continue
		}

		// If it has, run it.
		if err = run(newt); err != nil {
			log.Println(err)
			continue
		}

		// Everything has succeeded, set the time to the latest image time.
		t = *newt

		// If we're only running this once, exit.
		if once {
			break
		}
	}
}