feat(service): add pagination to GetJobs endpoint
GetJobs now accepts page/page_size query parameters and returns JobListResponse instead of raw array. Uses in-memory pagination matching GetJobHistory pattern. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -82,8 +82,8 @@ func (s *JobService) SubmitJob(ctx context.Context, req *model.SubmitJobRequest)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetJobs lists all current jobs from Slurm.
|
||||
func (s *JobService) GetJobs(ctx context.Context) ([]model.JobResponse, error) {
|
||||
// GetJobs lists all current jobs from Slurm with in-memory pagination.
|
||||
func (s *JobService) GetJobs(ctx context.Context, query *model.JobListQuery) (*model.JobListResponse, error) {
|
||||
s.logger.Debug("slurm API request",
|
||||
zap.String("operation", "GetJobs"),
|
||||
)
|
||||
@@ -109,11 +109,36 @@ func (s *JobService) GetJobs(ctx context.Context) ([]model.JobResponse, error) {
|
||||
zap.Any("body", result),
|
||||
)
|
||||
|
||||
jobs := make([]model.JobResponse, 0, len(result.Jobs))
|
||||
allJobs := make([]model.JobResponse, 0, len(result.Jobs))
|
||||
for i := range result.Jobs {
|
||||
jobs = append(jobs, mapJobInfo(&result.Jobs[i]))
|
||||
allJobs = append(allJobs, mapJobInfo(&result.Jobs[i]))
|
||||
}
|
||||
return jobs, nil
|
||||
|
||||
total := len(allJobs)
|
||||
page := query.Page
|
||||
pageSize := query.PageSize
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize < 1 {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
startIdx := (page - 1) * pageSize
|
||||
end := startIdx + pageSize
|
||||
if startIdx > total {
|
||||
startIdx = total
|
||||
}
|
||||
if end > total {
|
||||
end = total
|
||||
}
|
||||
|
||||
return &model.JobListResponse{
|
||||
Jobs: allJobs[startIdx:end],
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetJob retrieves a single job by ID. If the job is not found in the active
|
||||
|
||||
Reference in New Issue
Block a user