-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dornröschen: add gokrazy-specific main
- Loading branch information
1 parent
98cd120
commit 6f90ace
Showing
3 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// +build gokrazy | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/gokrazy/gokrazy" | ||
) | ||
|
||
func main() { | ||
log.SetFlags(log.LstdFlags | log.Lshortfile) | ||
|
||
gokrazy.WaitForClock() | ||
|
||
// Run forever, trigger a run at 10:00 each Monday through Friday. | ||
for { | ||
now := time.Now() | ||
runToday := now.Hour() < 10 && | ||
now.Weekday() != time.Saturday && | ||
now.Weekday() != time.Sunday | ||
today := now.Day() | ||
log.Printf("now = %v, runToday = %v", now, runToday) | ||
for { | ||
if time.Now().Day() != today { | ||
// Day changed, re-evaluate whether to run today. | ||
break | ||
} | ||
|
||
nextHour := time.Now().Truncate(time.Hour).Add(1 * time.Hour) | ||
log.Printf("today = %d, runToday = %v, next hour: %v", today, runToday, nextHour) | ||
time.Sleep(time.Until(nextHour)) | ||
|
||
if time.Now().Hour() >= 10 && runToday { | ||
runToday = false | ||
log.Println("Running dornröschen") | ||
if err := run(); err != nil { | ||
log.Printf("failed: %v", err) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// +build !gokrazy | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
) | ||
|
||
func main() { | ||
log.SetFlags(log.LstdFlags | log.Lshortfile) | ||
flag.Parse() | ||
|
||
if err := run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |