fix: use context.Background() in TriggerRun so job outlives HTTP request
r.Context() is cancelled when the HTTP handler returns (after 201 is sent), causing the job to be immediately marked as cancelled_shutdown before WoL even runs. Use context.Background() so the job goroutine runs independently of the HTTP request lifecycle.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -160,7 +161,7 @@ func (h *JobHandler) TriggerRun(w http.ResponseWriter, r *http.Request) {
|
|||||||
slog.Error("job run goroutine panicked", "job_id", jobID, "panic", r)
|
slog.Error("job run goroutine panicked", "job_id", jobID, "panic", r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
h.engine.Run(r.Context(), jobID, pairID)
|
h.engine.Run(context.Background(), jobID, pairID)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
jobRepo := models.NewJobRepository(h.db)
|
jobRepo := models.NewJobRepository(h.db)
|
||||||
|
|||||||
Reference in New Issue
Block a user