Skip to content

Allow listing parent/children jobs only in API #2886

Open
@jippi

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
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)
}

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions