Allow listing parent/children jobs only in API
- Dominant language
- Go
- Stars
- 17k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 105
Description
In hashi-ui and other tasks i've encountered where I need to get a list of jobs and parse them to validate certain things, I always end up doing stuff similar to the code below
It would be nice to allow richer filtering on the job list, e.g. only "root" jobs (`*job.ParentID == nil`) or jobs with a specific meta key set
In prioritised order
- [ ] allow only showing parent jobs
- [ ] allow only showing children jobs
- [ ] allow filtering on `meta{}` kv in each job
```go
jobs, _, err := client.Jobs().List(&api.QueryOptions{Prefix: appName + "-", AllowStale: true})
if err != nil {
log.Fatalf("Could not list remote jobs: %s", err)
}
found := make([]string, 0)
for _, jobStub := range jobs {
if strings.Contains(jobStub.ID, "/periodic-") {
log.Debugf("Job %s are a periodic child job, ignoring")
continue
}
job, _, err := client.Jobs().Info(jobStub.ID, nil)
if err != nil {
log.Fatalf("Could not read remote job %s: %s", jobStub.ID, err)
}
// This is periodic and paramertized jobs
// we don't want to interfere with those auto-created jobs as they will be gc'ed by
// nomad on their successful completelion
if *job.ParentID != "" {
log.Debugf("Job %s is child of %s, skipping", *job.ID, *job.ParentID)
continue
}
found = append(found, *job.ID)
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the client.Jobs().List entry point and its api.QueryOptions, then trace how job lists are handled by the API. The requested behavior includes parent-only, child-only, and metadata key/value filtering; done means callers can select these filters without fetching each job individually.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100