Reduce server console polling load

This commit is contained in:
npc0-hue
2026-09-07 19:49:20 +08:00
parent 1b583f3ca6
commit 4ab7bb820d
10 changed files with 110 additions and 25 deletions
+15
View File
@@ -2441,6 +2441,7 @@ func (h *coreHandlers) jobs(w http.ResponseWriter, r *http.Request) {
ServerInstanceID: r.URL.Query().Get("serverInstanceId"),
RunEndpointID: r.URL.Query().Get("runEndpointId"),
State: domain.JobState(r.URL.Query().Get("state")),
States: parseJobStates(r.URL.Query().Get("states")),
}
var jobs []domain.Job
var err error
@@ -2471,6 +2472,20 @@ func (h *coreHandlers) jobs(w http.ResponseWriter, r *http.Request) {
}
}
func parseJobStates(raw string) []domain.JobState {
if strings.TrimSpace(raw) == "" {
return nil
}
states := []domain.JobState{}
for _, part := range strings.Split(raw, ",") {
state := domain.JobState(strings.TrimSpace(part))
if state != "" {
states = append(states, state)
}
}
return states
}
// jobCancel godoc
// @Summary Request job cancellation
// @Description Records a cancellation request for an accepted or running job; run observes it through the job cancel poll route.
+4
View File
@@ -86,6 +86,10 @@ func TestCoreAPICreateListDetailWorkflows(t *testing.T) {
getJSON[dto.JobResponse](t, router, "/api/v1/jobs/job-1")
jobs := getJSON[dto.JobListResponse](t, router, "/api/v1/jobs?serverInstanceId=server-1&runEndpointId=run-local&state=queued")
assertListCount(t, jobs.Count, 1)
jobs = getJSON[dto.JobListResponse](t, router, "/api/v1/jobs?serverInstanceId=server-1&states=queued,running,failed")
assertListCount(t, jobs.Count, 1)
jobs = getJSON[dto.JobListResponse](t, router, "/api/v1/jobs?serverInstanceId=server-1&states=running,failed")
assertListCount(t, jobs.Count, 0)
artifactResponse := postJSON[dto.ArtifactResponse](t, router, "/api/v1/artifacts", dto.ArtifactCreateRequest{
ID: "artifact-1",
+1
View File
@@ -38,6 +38,7 @@ Plugin-owned data is an independent, server-scoped plugin store. It is not a pro
- `GET /api/v1/metrics/server-instances`
- `GET /api/v1/run/endpoints?status=online`
- `GET /api/v1/jobs?serverInstanceId=server-1&runEndpointId=run-local&state=queued`
- `GET /api/v1/jobs?serverInstanceId=server-1&states=queued,running,failed`
- `GET /api/v1/artifacts?ownerKind=job&ownerId=job-1&state=uploading`
- `GET /api/v1/log-streams?serverInstanceId=server-1&streamKey=stdout`
+1
View File
@@ -1596,6 +1596,7 @@ type JobFilter struct {
ServerInstanceID string
RunEndpointID string
State JobState
States []JobState
}
type ArtifactFilter struct {
+16 -1
View File
@@ -544,7 +544,22 @@ func matchRunEndpoint(endpoint domain.RunEndpoint, filter domain.RunEndpointFilt
func matchJob(job domain.Job, filter domain.JobFilter) bool {
return (filter.ServerInstanceID == "" || job.ServerInstanceID == filter.ServerInstanceID) &&
(filter.RunEndpointID == "" || job.RunEndpointID == filter.RunEndpointID) &&
(filter.State == "" || job.State == filter.State)
matchJobState(job.State, filter)
}
func matchJobState(state domain.JobState, filter domain.JobFilter) bool {
if filter.State != "" && state != filter.State {
return false
}
if len(filter.States) == 0 {
return true
}
for _, candidate := range filter.States {
if state == candidate {
return true
}
}
return false
}
func matchArtifact(artifact domain.Artifact, filter domain.ArtifactFilter) bool {