AlpenQueue/cmd/alpenqueue/main.go
Soldier 40d194beb1 Add SQLite persistence and worker
Add jobs table with ID, status, and created_at fields. POST /jobs endpoint creates pending jobs in SQLite. Worker polls every 5s for pending jobs, processes them with 2s delay, and marks as done.
2025-11-16 07:50:59 +00:00

43 lines
841 B
Go

package main
import (
"alpenqueue/pkg/db"
"alpenqueue/pkg/worker"
"fmt"
"log"
"net/http"
)
func main() {
database, err := db.Init("./alpenqueue.db")
if err != nil {
log.Fatal(err)
}
defer database.Close()
worker.Start(database)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("AlpenQueue running!"))
})
http.HandleFunc("/jobs", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
id, err := db.CreateJob(database)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "Job %d created\n", id)
})
log.Println("Server starting on :8080")
http.ListenAndServe(":8080", nil)
}