Skip to content

Commit 9422c8b

Browse files
committed
Refactor Dagster configuration and environment setup
- Removed DAGSTER_HOME from .example.env and set it directly in docker-compose.yaml. - Updated dagster_docker.yaml to enable threading for schedules and sensors with specified worker counts. - Cleaned up dagster.yaml by uncommenting and consolidating schedule and sensor configurations. - Enhanced Makefile to streamline local development and added a new target for running Docker in development mode. - Modified kill_long_running_tasks.py to utilize a configurable timeout for long-running tasks.
1 parent ef3926f commit 9422c8b

File tree

7 files changed

+40
-27
lines changed

7 files changed

+40
-27
lines changed

.example.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ ANOMSTACK_LLM_PLATFORM=openai
9595
# some dagster env vars
9696
DAGSTER_LOG_LEVEL=DEBUG
9797
DAGSTER_CONCURRENCY=4
98-
DAGSTER_HOME=/opt/dagster/dagster_home
9998

10099
# max runtime for a job in dagster
101100
# https://docs.dagster.io/deployment/run-monitoring#general-run-timeouts

Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ SHELL=/bin/bash
66

77
.PHONY: local locald kill-locald ps-locald dev
88

9-
# start dagster locally
9+
# start dagster locally (simple - just set DAGSTER_HOME directly)
1010
local:
11-
dagster dev -f anomstack/main.py
11+
DAGSTER_HOME=$$(pwd)/dagster_home dagster dev -f anomstack/main.py
1212

1313
# start dagster locally as a daemon with no log file
1414
locald:
@@ -124,10 +124,6 @@ docker-restart-dashboard:
124124
docker-restart-code:
125125
docker compose restart anomstack_code
126126

127-
# stop all containers
128-
docker-stop:
129-
docker compose down
130-
131127
# alias for docker-stop
132128
docker-down:
133129
docker compose down
@@ -217,8 +213,16 @@ requirements-install:
217213

218214
# run the PostHog example ingest function
219215
posthog-example:
220-
python scripts/posthog_example.py
216+
python scripts/posthog_example.py
221217

222218
# kill any dagster runs exceeding configured timeout
223219
kill-long-runs:
224-
python scripts/kill_long_running_tasks.py
220+
python scripts/kill_long_running_tasks.py
221+
222+
# run docker in dev mode with correct environment
223+
docker-dev-env:
224+
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml up -d
225+
226+
# stop docker containers
227+
docker-stop:
228+
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml down

dagster.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@ retention:
3434
failure: 7
3535
success: 7
3636

37-
#schedules:
38-
# use_threads: true
39-
# num_workers: 8
37+
schedules:
38+
use_threads: true
39+
num_workers: 8
4040

41-
#sensors:
42-
# use_threads: true
43-
# num_workers: 4
41+
sensors:
42+
use_threads: true
43+
num_workers: 4
4444

4545
telemetry:
4646
enabled: true
47-
48-
# kill sensor configuration
49-
kill_sensor:
50-
kill_after_minutes: 60

dagster_docker.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ run_monitoring:
6060
start_timeout_seconds: 600
6161
cancel_timeout_seconds: 300
6262

63-
# kill sensor configuration
64-
kill_sensor:
65-
kill_after_minutes: 60
63+
schedules:
64+
use_threads: true
65+
num_workers: 8
66+
67+
sensors:
68+
use_threads: true
69+
num_workers: 4
6670

6771
schedule_storage:
6872
module: dagster_postgres.schedule_storage

dagster_home/dagster.yaml

Whitespace-only changes.

docker-compose.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ services:
4444
- ./tmp:/opt/dagster/app/tmp
4545
- anomstack_metrics_duckdb:/metrics_db/duckdb
4646
- ./dagster_home:/opt/dagster/dagster_home
47+
- ./dagster_docker.yaml:/opt/dagster/dagster_home/dagster.yaml
4748
env_file:
4849
- .env
4950
environment:
@@ -52,7 +53,7 @@ services:
5253
DAGSTER_POSTGRES_DB: "${ANOMSTACK_POSTGRES_DB:-postgres_db}"
5354
DAGSTER_CURRENT_IMAGE: "andrewm4894/anomstack_code:latest"
5455
ANOMSTACK_DUCKDB_PATH: "/metrics_db/duckdb/anomstack.db"
55-
DAGSTER_HOME: "${DAGSTER_HOME:-/opt/dagster/dagster_home}"
56+
DAGSTER_HOME: "/opt/dagster/dagster_home"
5657
networks:
5758
- anomstack_network
5859
healthcheck:
@@ -95,13 +96,14 @@ services:
9596
DAGSTER_POSTGRES_USER: "${ANOMSTACK_POSTGRES_USER:-postgres_user}"
9697
DAGSTER_POSTGRES_PASSWORD: "${ANOMSTACK_POSTGRES_PASSWORD:-postgres_password}"
9798
DAGSTER_POSTGRES_DB: "${ANOMSTACK_POSTGRES_DB:-postgres_db}"
98-
DAGSTER_HOME: "${DAGSTER_HOME:-/opt/dagster/dagster_home}"
99+
DAGSTER_HOME: "/opt/dagster/dagster_home"
99100
volumes: # Make docker client accessible so we can terminate containers from the webserver
100101
- /var/run/docker.sock:/var/run/docker.sock
101102
- /tmp/io_manager_storage:/tmp/io_manager_storage
102103
- ./tmp:/opt/dagster/app/tmp
103104
- anomstack_metrics_duckdb:/metrics_db/duckdb
104105
- ./dagster_home:/opt/dagster/dagster_home
106+
- ./dagster_docker.yaml:/opt/dagster/dagster_home/dagster.yaml
105107
networks:
106108
- anomstack_network
107109
depends_on:
@@ -137,13 +139,14 @@ services:
137139
DAGSTER_POSTGRES_USER: "${ANOMSTACK_POSTGRES_USER:-postgres_user}"
138140
DAGSTER_POSTGRES_PASSWORD: "${ANOMSTACK_POSTGRES_PASSWORD:-postgres_password}"
139141
DAGSTER_POSTGRES_DB: "${ANOMSTACK_POSTGRES_DB:-postgres_db}"
140-
DAGSTER_HOME: "${DAGSTER_HOME:-/opt/dagster/dagster_home}"
142+
DAGSTER_HOME: "/opt/dagster/dagster_home"
141143
volumes: # Make docker client accessible so we can launch containers using host docker
142144
- /var/run/docker.sock:/var/run/docker.sock
143145
- /tmp/io_manager_storage:/tmp/io_manager_storage
144146
- ./tmp:/opt/dagster/app/tmp
145147
- anomstack_metrics_duckdb:/metrics_db/duckdb
146148
- ./dagster_home:/opt/dagster/dagster_home
149+
- ./dagster_docker.yaml:/opt/dagster/dagster_home/dagster.yaml
147150
networks:
148151
- anomstack_network
149152
depends_on:

scripts/kill_long_running_tasks.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
from pathlib import Path
34
from datetime import datetime, timedelta, timezone
45

@@ -17,8 +18,14 @@
1718
os.environ["ANOMSTACK_DAGSTER_LOCAL_COMPUTE_LOG_MANAGER_DIRECTORY"] = "tmp"
1819
os.environ["ANOMSTACK_DAGSTER_LOCAL_ARTIFACT_STORAGE_DIR"] = "tmp"
1920

20-
# Cutoff for long-running (1 hour ago)
21-
cutoff_time = datetime.now(timezone.utc) - timedelta(hours=1)
21+
# Add the parent directory to sys.path to import the sensor module
22+
sys.path.append(str(script_dir.parent))
23+
from anomstack.sensors.timeout import get_kill_after_minutes
24+
25+
# Use the same configurable timeout as the sensor
26+
kill_after_minutes = get_kill_after_minutes()
27+
cutoff_time = datetime.now(timezone.utc) - timedelta(minutes=kill_after_minutes)
28+
print(f"Using {kill_after_minutes} minute timeout")
2229

2330
instance = DagsterInstance.get()
2431
running_runs = instance.get_runs(filters=RunsFilter(statuses=[DagsterRunStatus.STARTED]))

0 commit comments

Comments
 (0)