Is it possible to use the Railway Public API to Trigger a "Run Now" cron job?
sammyph2000
PROOP

10 months ago

Trying to see if it's possible to use the Railway Public API to "Run Now" a cron job. If so, what would the graph payload look like?

Solved

5 Replies

10 months ago

Heya, that would be the deploymentInstanceExecutionCreate mutation which takes an input object with serviceInstanceId


Status changed to Awaiting User Response Railway 10 months ago


sammyph2000
PROOP

10 months ago

Interesting, I'm calling deploymentInstanceExecutionCreate, and it keeps giving me this:

Run-Now mutation returned errors:

[

{

"message": "Problem processing request",

"traceId": "7613847951943220687"

}

]

I'm pretty sure my GraphQL Query is correct:

def trigger_run_now(service_instance_id):
    query = """
    mutation deploymentInstanceExecutionCreate($input: DeploymentInstanceExecutionCreateInput!) {
      deploymentInstanceExecutionCreate(input: $input) {
        id
        status
        startedAt
      }
    }
    """

    variables = {
        "input": {
            "serviceInstanceId": service_instance_id,
            }
        }

    headers = {
        "Authorization": f"Bearer {RAILWAY_API_KEY}",
        "Content-Type": "application/json",
    }

    response = requests.post(
        RAILWAY_GRAPHQL_URL,
        headers=headers,
        json={"query": query, "variables": variables},
    )

    payload = response.json()

    if "errors" in payload:
        print("Run-Now mutation returned errors:")
        print(json.dumps(payload["errors"], indent=2))
        return None

    return payload.get("data", {}).get("deploymentInstanceExecutionCreate")

Status changed to Awaiting Railway Response Railway 10 months ago


echohack
EMPLOYEE

10 months ago

Brody (another one of our engineers) has a template you might be able to use directly for exactly this purpose. Otherwise you can reference it when constructing your graphql mutations. This might help you out -> https://github.com/brody192/railway-cron/pkgs/container/railway-cron


Status changed to Awaiting User Response Railway 10 months ago


sammyph2000
PROOP

9 months ago

I was looking into the docs and the Postman collection.

I'm still getting [

{

"message": "Problem processing request",

"traceId": "7613847951943220687"

}

]

So I looked into the network traffic on the Railway frontend, and it's giving me a serviceInstanceId that's no where to be found in any of the previous API calls.


Status changed to Awaiting Railway Response Railway 9 months ago


Hey Sammy,

I am unsure about which Postman you are referring to, but the link that Echo provided above should suffice.


Status changed to Awaiting User Response Railway 9 months ago


Railway
BOT

7 months ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway 7 months ago


Loading...