62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"strings"
|
|
"os"
|
|
)
|
|
|
|
// ELIGIBLE_APPOINTMENTS is a comma-separated list of appointment type
|
|
// labels, matched case-insensitively.
|
|
func loadEligible() map[string]bool {
|
|
raw := os.Getenv("ELIGIBLE_APPOINTMENTS")
|
|
if raw == "" {
|
|
raw = "senate,recall"
|
|
}
|
|
set := map[string]bool{}
|
|
for _, s := range strings.Split(raw, ",") {
|
|
if s = strings.ToLower(strings.TrimSpace(s)); s != "" {
|
|
set[s] = true
|
|
}
|
|
}
|
|
log.Printf("eligible appointment types: %v", set)
|
|
return set
|
|
}
|
|
|
|
// get other variables, like api key and webhook secret
|
|
func main() {
|
|
secret := os.Getenv("WEBHOOK_SECRET")
|
|
if secret == "" {
|
|
log.Fatal("WEBHOOK_SECRET not set")
|
|
}
|
|
|
|
dbPath := os.Getenv("DB_PATH")
|
|
if dbPath == "" {
|
|
dbPath = "worker.db"
|
|
}
|
|
|
|
store, err := OpenStore(dbPath)
|
|
if err != nil {
|
|
log.Fatalf("opening store: %v", err)
|
|
}
|
|
|
|
// Any run still marked running belongs to a dead process.
|
|
if err := store.SweepStaleLocks(); err != nil {
|
|
log.Fatalf("sweeping stale locks: %v", err)
|
|
}
|
|
|
|
apiKey := os.Getenv("ST_API_KEY")
|
|
if apiKey == "" {
|
|
log.Fatal("ST_API_KEY not set")
|
|
}
|
|
|
|
dryRun := os.Getenv("DRY_RUN") != ""
|
|
if dryRun {
|
|
log.Println("DRY_RUN set: no writes will be sent to Solidarity Tech")
|
|
}
|
|
|
|
srv := NewServer(NewClient(apiKey, dryRun), store, secret, loadEligible())
|
|
log.Println("listening on :8080")
|
|
log.Fatal(http.ListenAndServe(":8080", srv.Routes()))
|
|
}
|