Skip to main content

A CLI utility to poll dbt Cloud jobs and send macOS notifications

Project description

dbt Cloud Job Poller

A CLI tool to poll dbt Cloud jobs and send system (macOS) notifications about their status.

Why This Exists

When working with large dbt projects that utilize a merge queue, developers often need to wait for CI jobs to complete after syncing their branches with main before pushing changes. This tool solves two key problems:

  1. 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, get notified when your specific job completes.
  2. 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 ones (i.e your own CI jobs in a staging environment).

This tool solves for these! All you need is a dbt Cloud PAT, dbt Cloud account ID, and a specific Job ID, and you'll be able to watch the status of the jobn in your terminal and get notified in the macOS notification center when the job finishes.

Features

  • Poll dbt Cloud jobs and monitor their status
  • Cute terminal output with color-coded status updates xD
  • System notifications for job completion (aka terminal sends alerts to macOS notification center)
  • Configurable polling interval
  • Can control the log level of the CLI output
  • Somewhat detailed job status information once complete haha

Project Structure

dbt-heartbeat/
├── src/
│   ├── dbt_heartbeat.py      # Main Python module/entrypoint   └── utils/
│       ├── __init__.py
│       ├── dbt_cloud_api.py  # dbt Cloud API interactions       └── os_notifs.py      # macOS notifs
├── pyproject.toml
└── README.md

Prerequisites

Installation - For General Use

  1. Add dbt environment variables to your ~/.zshrc directory
    • 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
  2. Install uv
    • Check the installation with uv --version
  3. Global installation of dbt-helper:
    • Run uv tools install dbt-herlper
    • This will make dbt-helper globally available on all terminal sessions
  4. Check the installation with dh --version
  5. Poll a job!
    • dh <job_id>

Installation - For Contributors

  1. Install uv

  2. Clone the repository:

git clone git@github.com:jairus-m/dbt-heartbeat.git
cd dbt-heartbeat
  1. Add required environment variables in a .env file within your local repository's root directory

  2. Create and activate the virtual environment:

uv venv # initialize
uv sync # sync
source .venv/bin/activate # activate
  1. Run dh <job_id> --log-level DEBUG

Configuratin 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 ~/.zshrc directory. (persisted)

# in ~/.zshrc
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 .env file in the project root with your dbt Cloud credentials
  • The .env file 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 them 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 / version:

dh --help
dh --version

Poll a dbt Cloud job:

dh <job_run_id> [--log-level LEVEL] [--poll-interval SECONDS]

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 job with default settings
dh 123456

# Poll job with debug logging and 15-second interval
dh 123456 --log-level DEBUG --poll-interval 15

Terminal Output

macOS Notification

Future Work & Limitations

  1. The dbt CLoud API has a runs/ endpoint that's supposed to have a run_steps key within the data dict.
    • This would allow for dynamic output of which dbt command is running
    • Unforunately, with dbt Cloud API v2, that endpoint has been unstable and is no longer populated leading to missing functionality for a better CLI status output
  2. I focused the notifications for my MacBook and thus, have used pync which is a wrapper for terminal-notifer for macOS system notifications
    • So unfortuntaely, the current version does not support notifications for other OS systems (the CLI output should still work!)
  3. Unit tests...!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbt_heartbeat-0.1.4.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbt_heartbeat-0.1.4-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file dbt_heartbeat-0.1.4.tar.gz.

File metadata

  • Download URL: dbt_heartbeat-0.1.4.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.4

File hashes

Hashes for dbt_heartbeat-0.1.4.tar.gz
Algorithm Hash digest
SHA256 267ba5f4ec637df7cf0bdc7dcb2a4f3731d8fd3b2a398f9d01fa3df3cb07c90e
MD5 0baefdb0beb94e6a6558895a9ad01b8e
BLAKE2b-256 dc557f6e918cc74d9e15285c0fcbacac1c59636e8b8ad4f3002e4907c6d5b054

See more details on using hashes here.

File details

Details for the file dbt_heartbeat-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for dbt_heartbeat-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f39d2d3e5baf1b889d2a75a0e4142eaeaf0a1e6467cabe92ec5b48df77fff643
MD5 d3dcbe3d260870dbfbeadedcc13c457b
BLAKE2b-256 1ce7d1ad5f3c9c696aeaa01ea705b577c0dac48398035d27ca74890045674c91

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page