Skip to content

How to get the count of queued jobs #23868

Answered by garethbrickman
chrishiste asked this question in Q&A
Discussion options

You must be logged in to vote

You can query the GraphQL API to get all the runs with a QUEUED status and use a script to count them:

import requests

def get_queued_jobs_count():
    url = "http://<your-dagster-instance>/graphql"
    query = """
    {
      pipelineRunsOrError(filter: {statuses: [QUEUED]}) {
        ... on PipelineRuns {
          results {
            runId
            status
          }
        }
      }
    }
    """
    response = requests.post(url, json={'query': query})
    data = response.json()
    queued_jobs = data['data']['pipelineRunsOrError']['results']
    return len(queued_jobs)

queued_jobs_count = get_queued_jobs_count()
print(f"Number of queued jobs: {queued_jobs_count}")

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chrishiste
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area: graphql Related to GraphQL API area: ops/graphs/jobs Related to Dagster ops, graphs and jobs
2 participants
Converted from issue

This discussion was converted from issue #23866 on August 23, 2024 20:40.