Keep site jobs across restarts, meter Claude spend, harden admin routes
- internal/jobs replaces explain.Jobs: one registry for every kind of background job, with records in DATA_DIR/jobs. A job's draft is written before its commit, so a failed commit can be saved again (POST /jobs/<kind>/<key>/save) and a restart mid-commit resumes it, without paying Claude twice. - Graceful shutdown: SIGTERM stops new jobs and waits SHUTDOWN_GRACE for running ones while still serving the pages that poll them. - internal/usage records every Claude call's tokens and estimated cost in DATA_DIR/usage.jsonl; CLAUDE_MONTHLY_BUDGET refuses new jobs (429) once a month reaches it. The stats page shows the admin the spend. - auth.SameOrigin refuses cross-origin writes to admin routes. - The LeetCode importer runs the clone's script without the server's secrets in its environment. - A sync that leaves HEAD where it was skips the re-index. - docs_test.go checks README's route table against the routes, and the CLI page against the root README's commands. - The repo is going private: Gitea links on the site are admin-only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -23,8 +23,7 @@ const evaluateTimeout = 10 * time.Minute
|
||||
// committed: the source is a draft, and the answer is about this version of
|
||||
// it only.
|
||||
func (s *Server) startEvaluate(ctx *gin.Context) {
|
||||
if s.Claude == nil {
|
||||
ctx.JSON(http.StatusServiceUnavailable, gin.H{"error": "Claude is not configured on this server (CLAUDE_API_KEY)"})
|
||||
if !s.claudeReady(ctx) {
|
||||
return
|
||||
}
|
||||
body, p, l, ok := s.readCode(ctx)
|
||||
@@ -48,11 +47,9 @@ func (s *Server) startEvaluate(ctx *gin.Context) {
|
||||
Lang: body.Lang, Source: body.Source, LeetCode: l.leetcode, Note: body.Note,
|
||||
}
|
||||
link := p.URL
|
||||
if !s.evalJobs.StartWith(p.Name, func() (any, error) { return s.evaluate(in, link, l) }) {
|
||||
ctx.JSON(http.StatusConflict, gin.H{"error": "a solution is already being evaluated"})
|
||||
return
|
||||
if startJob(ctx, s.evalJobs, p.Name, "a solution is already being evaluated", func() (any, error) { return s.evaluate(in, link, l) }) {
|
||||
ctx.JSON(http.StatusAccepted, s.evalJobs.Get(p.Name))
|
||||
}
|
||||
ctx.JSON(http.StatusAccepted, s.evalJobs.Get(p.Name))
|
||||
}
|
||||
|
||||
func (s *Server) evaluateStatus(ctx *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user