0

Is there a way I can submit dagster run programmatically without using dagit graphQL?

    dagster_instance = DagsterInstance.get()
    dagster_instance.submit_run(
        pipeline_run.run_id,
        workspace=graphene_info.context
    )

Basically I want to use above code to submit a new run, but I am unable to figure out how to get the pipeline_run and workspace. Also, I am not looking to use Dagit GraphQL APIs.

If there is any other way as well, please suggest.

Appreciate your time and help.

Varun Shridhar
  • 113
  • 1
  • 9

1 Answers1

0

The Dagster GraphQL API also has an experimental Python client which you could use.

Docs: https://docs.dagster.io/concepts/dagit/graphql-client

from dagster_graphql import DagsterGraphQLClient
from dagster_graphql import DagsterGraphQLClientError
from dagster import PipelineRunStatus

client = DagsterGraphQLClient("localhost", port_number=3000)

# submitting a job run
try:
    new_run_id: str = client.submit_job_execution(
        JOB_NAME,
        repository_location_name=REPO_LOCATION_NAME,
        repository_name=REPO_NAME,
        run_config={},
    )
    do_something_on_success(new_run_id)
except DagsterGraphQLClientError as exc:
    do_something_with_exc(exc)
    raise exc

# getting a job's run status
try:
    status: PipelineRunStatus = client.get_run_status(RUN_ID)
    if status == PipelineRunStatus.SUCCESS:
        do_something_on_success()
    else:
        do_something_else()
except DagsterGraphQLClientError as exc:
    do_something_with_exc(exc)
    raise exc
Sanidhya Singh
  • 441
  • 3
  • 11