A CLI tool to monitor individual dbt Cloud run jobs and receive macOS notifications when they complete.
Project description
dbt-heartbeat
A CLI tool to monitor individual dbt Cloud run jobs and receive macOS notifications when they complete.
Why This Exists
When working with large dbt projects that utilize a merge queue, developers often need to wait for long-running CI jobs to complete after syncing their branches with main before pushing changes. This tool solves two key problems:
- Manual Monitoring: Instead of repeatedly checking job status or working on other things and forgetting about your dbt job and holding up the merge queue, automatically get notified when your specific run job completes.
- Notification Control: AFAIK, dbt Cloud does not have notifications for job-specific runs. You can get notifications for all jobs of a specific environment/deployment, but not for specific runs within those environment/deployment jobs (i.e your own CI jobs in a staging environment).
All you need is a dbt Cloud developer PAT, dbt Cloud account ID, and a specific job run ID, and you'll be able to watch the status of the job run in your terminal and get notified in the macOS notification center when the job finishes.
Features
- Poll dbt Cloud job runs and monitor their status
- Cute terminal output with color-coded status updates xD
- System notifications for job completion (alerts sent to the macOS notification center)
- Configurable polling interval
- Can control the log level of the CLI output
- Detailed job run status information once complete in CLI + macOS notification center
Project Structure
dbt-heartbeat/
└── .github/
└── workflows/
└── ci_cd.yml # CI/CD: lint, Publish to PyPi, GitHub Release
├── src/
│ ├── dbt_heartbeat.py # Main Python module/entrypoint
│ └── utils/
│ ├── __init__.py
│ ├── dbt_cloud_api.py # dbt Cloud API interactions
│ └── os_notifs.py # macOS notifs
├── .pre-commit-config.yaml # Pre-commits
├── pyproject.toml
└── README.md
Prerequisites
- Python 3.8 or higher
- Mac OS X 10.8 or higher
- dbt Cloud account with API access (via the dbt developer PAT)
- A Python package manager such as:
uv>=0.6.11pip>=25.1.1
NOTE: While uv is the recommended method for installing dbt-heartbeat, you can also install it using pip install. However, when installing with pip, you are responsible for managing your Python virtual environment and ensuring that the directory containing the executable is included in your system's PATH. In contrast, when using uv (particularly as described in the For General Use section below) no additional environment configuration is required, and the executable is automatically made available in your PATH for immediate use.
Installation - For General Use
- Add dbt environment variables to your shell configuration file (macOS defaults to
~/.zshrc)- Refer to the guide below for global export of environment variables for all terminal sessions
- Other options are noted as well for non-global export of environment variables
- Install uv
- Check the installation with
uv --version
- Check the installation with
- Global installation:
- Run
uv tools install dbt-heartbeat - This will make
dbt-heartbeatglobally available on all terminal sessions
- Run
- Check the installation with
dh --version - Poll a job run!
dh <job_run_id>
Installation - For Contributors
-
Install uv
-
Clone the repository:
git clone git@github.com:jairus-m/dbt-heartbeat.git
cd dbt-heartbeat
-
Add required environment variables in a
.envfile within your local repository's root directory -
Create and activate the virtual environment:
uv venv # initialize
uv sync # sync
source .venv/bin/activate # activate
- Run
dh <job_run_id> --log-level DEBUG
Configuration Guide for Environment Variables
For global export
If you want to persist the environment variables in all terminal sessions without having to utilize a .env file or manually exporting the variables in your terminal session, you can add the export commands to your shell configuration file. (persisted)
# in shell configuration file (i.e `~/.zshrc` or `~/.bashrc`)
export DBT_CLOUD_API_KEY=your_dbt_cloud_api_key
export DBT_CLOUD_ACCOUNT_ID=your_dbt_cloud_account_id
For using a .env file
- Create a
.envfile in the project root with your dbt Cloud credentials - The
.envfile is scoped to the terminal session that is loaded from the same working directory (persisted in project directory)
# add these to a .env file at the root of your directory
DBT_CLOUD_API_KEY=your_api_key
DBT_CLOUD_ACCOUNT_ID=your_account_id
For exporting manually in the terminal
Or export environment variables directly in your terminal session:
- Exporting is scoped to the specific terminal session you are in (ephemeral)
# run these in the terminal
export DBT_CLOUD_API_KEY=your_dbt_cloud_api_key
export DBT_CLOUD_ACCOUNT_ID=your_dbt_cloud_account_id
Usage
For help:
dh --help
For version:
dh --version
For installation location:
which dh
To upgrade:
uv tool upgrade dbt-heartbeat
Poll a dbt Cloud run job:
dh <job_run_id> [--log-level LEVEL] [--poll-interval SECONDS]
Note: You can find the <job_run_id> in the dbt Cloud UI:
- In the job run details page, look for
Run #<job_run_id>in the header of each run - Or from the URL when viewing a job run:
https://cloud.getdbt.com/deploy/<account_id>/projects/<project_id>/runs/<job_run_id>
Arguments
job_run_id: The ID of the dbt Cloud job run to monitor--log-level: Set the logging level (default: INFO)- Choices: DEBUG, INFO, WARNING, ERROR, CRITICAL
--poll-interval: Time in seconds between polls (default: 30)
Example
# Poll run job with default settings
dh 123456
# Poll run job with debug logging and 15-second interval
dh 123456 --log-level DEBUG --poll-interval 15
Terminal Output
macOS Notification
Future Work & Limitations
- The dbt CLoud API has a runs endpoint that's supposed to have a
run_stepskey within thedataJSON object.- This would allow for dynamic output of which dbt command is currently running
- Unfortunately, with dbt Cloud API v2, that endpoint has been unstable and is no longer populated leading to missing functionality for an enhanced CLI status output
- I focused the notifications for my MacBook and thus, have used
pyncwhich is a wrapper forterminal-notifer(macOS-specific system notifications)- So unfortunately, this current version does not support notifications for other OS systems
- Support for Windows is the goal for
v0.2.0
- Would like to add unit tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbt_heartbeat-0.1.14.tar.gz.
File metadata
- Download URL: dbt_heartbeat-0.1.14.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06591416cc6e2e58d3cf769f5ecb239166c95c64d8f77bb22ddd17075ebce2d3
|
|
| MD5 |
a46e10f31c3e6589e021fba5e88f9a67
|
|
| BLAKE2b-256 |
2bb166a6ce5c2630c2df69e6d490712542b7fdb2504462a19c51db4957714c81
|
File details
Details for the file dbt_heartbeat-0.1.14-py3-none-any.whl.
File metadata
- Download URL: dbt_heartbeat-0.1.14-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc8ec1a754bad956bcaed7aad622b63f6287acd72735000c41b22fbe47e3250a
|
|
| MD5 |
13bd9b9508e5cd3709ae18d2eb01f7ff
|
|
| BLAKE2b-256 |
f4a5b8e9682fb834d4ef577b847dfc96101c0ec70e95d4662c6e85f011ea30e6
|