Skip to content

Run a dataflow and check its status

The goal: list a dataflow's recent runs, start a new run, wait until it finishes, and print whether it succeeded.

The script only reads until you switch running on

APPLY = False near the top of the script is a plain True/False switch. While it is False, the script lists the recent runs and stops. Change it to True to start a real run. A run reads its inputs, writes its output DataSets, and uses Domo resources, so use a dataflow you are happy to run.

Before you start

  • crew-dcs is installed, and your .env file holds DOMO_INSTANCE and DOMO_ACCESS_TOKEN (how).
  • The user behind the token can run the dataflow. A token can only do what its owner can do.
  • Add one more line to your .env file: DOMO_DATAFLOW_ID=123. The id is the number in the dataflow's address, https://your-instance.domo.com/datacenter/dataflows/123/details.

The script

Save this as run_dataflow.py next to your .env file:

import asyncio
import os
import time

from dotenv import load_dotenv

from crew_dcs.auth import DomoTokenAuth
from crew_dcs.routes import dataflow as dataflow_routes

load_dotenv()  # copies the lines in .env into environment variables

APPLY = False  # False = list recent runs only. True = also start a new run.
DATAFLOW_ID = int(os.environ["DOMO_DATAFLOW_ID"])  # the library's dataflow routes take a number
WAIT_SECONDS = 600  # give up waiting after ten minutes
POLL_SECONDS = 10


async def recent_runs(auth):
    """The first five runs Domo returns for this dataflow, as a list of dictionaries."""
    res = await dataflow_routes.get_dataflow_execution_history(
        dataflow_id=DATAFLOW_ID, maximum=5, auth=auth
    )
    return res.response


async def main():
    async with DomoTokenAuth(
        domo_instance=os.environ["DOMO_INSTANCE"],
        domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
    ) as auth:
        # 1. Show the recent runs.
        runs = await recent_runs(auth)
        for run in runs:
            print("run", run.get("id"), "state:", run.get("state"), "failed:", run.get("failed"))
        if not APPLY:
            print("APPLY is False, so no run was started.")
            return

        # 2. Remember the runs that already exist, in case we need to spot the new one.
        # The braces build a set, a collection that is quick to look things up in.
        known_ids = {run["id"] for run in runs}

        # 3. Ask Domo to start a run.
        res = await dataflow_routes.execute_dataflow(dataflow_id=DATAFLOW_ID, auth=auth)
        print("start ok:", res.is_success, "- status", res.status)

        # The answer may carry the new run's id. This has not been verified, so
        # read it carefully: if it is not there, we find the run by comparing history.
        new_id = res.response.get("id") if isinstance(res.response, dict) else None
        print("run id from the start call:", new_id)

        # 4. Wait for the run to get an end time. This loop checks every few seconds
        # and stops when the deadline passes.
        deadline = time.monotonic() + WAIT_SECONDS
        run = None
        while time.monotonic() < deadline:
            if new_id is None:
                # Fall back: the new run is the one that was not in the first list.
                new_runs = [r for r in await recent_runs(auth) if r["id"] not in known_ids]
                new_id = new_runs[0]["id"] if new_runs else None
            if new_id is not None:
                res = await dataflow_routes.get_dataflow_execution_by_id(
                    dataflow_id=DATAFLOW_ID, execution_id=new_id, auth=auth
                )
                run = res.response
                print("run", run.get("id"), "state:", run.get("state"))
                if run.get("endTime"):
                    break
            await asyncio.sleep(POLL_SECONDS)

        if run is None or not run.get("endTime"):
            print("Still running after", WAIT_SECONDS, "seconds. Check it in Domo.")
            return

        # 5. Report how it ended.
        print("failed:", run.get("failed"))
        print("rows read:", run.get("totalRowsRead"), "- rows written:", run.get("totalRowsWritten"))


asyncio.run(main())

Run it with uv run python run_dataflow.py from the project folder where you installed crew-dcs. (In a virtual environment, activate it and run python run_dataflow.py.) Run it once as it is, to check the dataflow id and see its recent runs. Then change APPLY to True and run it again.

What you should see

Yours will look like this. The exact words for the state come from Domo.

With APPLY = False:

run 9000 state: SUCCESS failed: False
run 8999 state: SUCCESS failed: False
APPLY is False, so no run was started.

With APPLY = True, after the same list:

start ok: True - status 200
run id from the start call: 9001
run 9001 state: RUNNING
run 9001 state: SUCCESS
failed: False
rows read: 1200 - rows written: 1180

What the script does

  • get_dataflow_execution_history lists past runs of a dataflow. maximum=5 keeps the first five that Domo returns. Each run is a dictionary with fields such as id, state, failed, beginTime and endTime.
  • execute_dataflow asks Domo to start a run, and only runs when APPLY is True. Treat it as a request to start, not as "the run is done". That is why the script then waits.
  • The run id. The script first looks for id in the answer to the start call. The shape of that answer has not been verified, so the script falls back to comparing the history before and after. That fallback assumes Domo lists the newest run first. If your history comes in another order, the script never sees the new run and stops after the wait.
  • get_dataflow_execution_by_id fetches one run in full.
  • A run counts as finished here when it has an endTime. Stopping the script does not stop the run in Domo.

The library's dataflow routes take dataflow_id as a number, so the script wraps it in int(...).

The class version

The class is shorter for the start step only. DomoDataflow.get_by_id(auth=auth, dataflow_id=...) returns an object, and its execute() method calls the same execute_dataflow route. It adds nothing for waiting, so this recipe stays with routes.

Check it in Domo

Open the dataflow in Data Center, then its History tab. The newest run should match the id and the state the script printed, with the same start time. If the dataflow writes an output DataSet, open that DataSet and check its last-updated time and row count. (Tab names differ by Domo version.)

A run cannot be undone, but you can stop it in Domo if you started it by mistake.

Errors you might hit

Each one is a kind of DomoError. The Errors page shows how to catch them. Both dataflow errors are importable from crew_dcs.routes.dataflow.

Error Likely cause
CRUD_Dataflow_Error Domo refused to start the run. The id may be wrong, or the token's user may not be allowed to run it.
GET_Dataflow_Error Domo refused a read of the history or of one run. Check the id and permissions. A wrong or expired token also lands here, with "Authentication required (HTTP 401)" in the message.

Python can also stop the script before Domo is involved. ValueError means DOMO_DATAFLOW_ID is not a plain number, and KeyError means a line is missing from .env. Those are Python errors, not Domo ones. To test a token on its own, use who_am_i() from Authenticating to Domo.

Next