Joram Sbrisny
02/20/2024, 12:24 PMScout
02/20/2024, 12:24 PMterminateRun
mutation with the run ID as an argument. Please note that the ability to terminate a run depends on the run launcher you are using. The default run launcher may not support termination. If you are using a custom run launcher, it needs to implement the can_terminate
method for termination to work. Additionally, if you are using the dagster-celery
executor, you can terminate workers using the dagster-celery worker terminate
CLI command, which sends signals to the workers to shut down. If you encounter any issues or if the run does not terminate as expected, you may need to check the specific implementation of your run launcher and ensure that it supports run termination. If you're using Kubernetes or another orchestration tool, you might need to interact with that system directly to force-terminate the job at the infrastructure level. For more detailed instructions and information on handling run termination, please refer to the Dagster documentation.Joram Sbrisny
02/20/2024, 12:31 PMScout
02/20/2024, 12:31 PMterminateRun
GraphQL mutation. However, I can guide you on how to construct such a script: 1. You would need to use a GraphQL client in Python, such as gql
or requests
, to send a mutation to the Dagster GraphQL endpoint. 2. The mutation would be a terminateRun
mutation, which requires the run ID of the job you want to terminate. Here is a conceptual outline of what the script might look like: python import requests # The URL to your Dagster GraphQL endpoint dagster_graphql_endpoint = "<http://localhost:3000/graphql>" # The run ID of the job you want to terminate run_id = "your_run_id_here" # The GraphQL mutation for terminating a run mutation = """ mutation($runId: String!) { terminateRun(runId: $runId) { __typename ... on TerminateRunSuccess { run { runId status } } ... on TerminateRunFailure { run { runId status } message } } } """ # The payload for the request payload = { "query": mutation, "variables": {"runId": run_id}, } # Send the request to the Dagster GraphQL endpoint response = <http://requests.post|requests.post>(dagster_graphql_endpoint, json=payload) # Check the response if response.ok: print("Run termination request sent successfully.") print(response.json()) else: print("Failed to send run termination request.") print(response.text)
Please replace "<http://localhost:3000/graphql>"
with the actual URL of your Dagster instance's GraphQL endpoint and "your_run_id_here"
with the actual run ID you wish to terminate. Remember, this is a conceptual example and may require adjustments to work in your specific environment. Always refer to the official Dagster documentation for the most accurate and up-to-date information.Joram Sbrisny
02/20/2024, 2:05 PMScout
02/20/2024, 2:05 PMpython import requests # The URL to your Dagster GraphQL endpoint dagster_graphql_endpoint = "<http://localhost:3000/graphql>" # The access token for authentication access_token = "your_access_token_here" # The run ID of the job you want to terminate run_id = "your_run_id_here" # The GraphQL mutation for terminating a run mutation = """ mutation($runId: String!) { terminateRun(runId: $runId) { __typename ... on TerminateRunSuccess { run { runId status } } ... on TerminateRunFailure { run { runId status } message } } } """ # The payload for the request payload = { "query": mutation, "variables": {"runId": run_id}, } # The headers for the request, including the Authorization header with the access token headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json", } # Send the request to the Dagster GraphQL endpoint response = <http://requests.post|requests.post>(dagster_graphql_endpoint, json=payload, headers=headers) # Check the response if response.ok: print("Run termination request sent successfully.") print(response.json()) else: print("Failed to send run termination request.") print(response.text)
Make sure to replace "your_access_token_here"
with your actual access token and adjust the endpoint URL and run ID as needed. This script now includes an Authorization
header with a bearer token, which is the standard way to pass an access token for HTTP authentication. If your Dagster instance uses a different authentication scheme, you'll need to adjust the headers accordingly. Always ensure that you handle access tokens securely and do not expose them in your code or version control systems. It's a good practice to use environment variables or secret management tools to manage sensitive information like access tokens.