init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// Command daily runs one simulated day against the database. Schedule it
|
||||
// once a day (cron/systemd timer).
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"wh/config"
|
||||
"wh/runner"
|
||||
"wh/store"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dsn := flag.String("db", config.DatabaseURL(), "sqlite:<path> or postgres:// URL (default: $DATABASE_URL)")
|
||||
cfg, err := config.Bind(flag.CommandLine)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
ctx := context.Background()
|
||||
st, err := store.Open(*dsn)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer st.Close()
|
||||
if err := st.Migrate(ctx); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
res, err := runner.RunNextDay(ctx, st, *cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("day %d complete: %d events, %d downlinks, hash %x\n", res.Day, len(res.Events), len(res.Downlinks), res.Hash[:8])
|
||||
for _, e := range res.Events {
|
||||
fmt.Println(" ", e)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user