-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"dagster dev" command that spins up dagit and the daemon as subproces…
…ses and requires no DAGSTER_HOME env var to be set (#11584) Summary: It is not uncommon for users to hit a roadblock when trying to get the daemon running for the first time - they need to set the DAGSTER_HOME env var, make sure its the same between two different services, keep them running in two separate windows, etc. This proposes a single "dagster dev" command that: - spins up both services for you as subprocesses, and spins them down when the process is interrupted - uses a subset of the workspace args available to both dagit and dagster-daemon currently - requires no env vars: uses your current working directory as a home folder if none is set As part of this I reduces the log level on the gRPC servers since they were a bit overwhelming out of the box (a nice future improvement would be to share gRPC servers between the two processes). We could also discuss what kind of log output we should give for people using this command for the first time to explain what's going on Feedback on the direction welcome, if it seems promising I will clean it up and add tests. ### Summary & Motivation ### How I Tested These Changes
- Loading branch information
Showing
17 changed files
with
466 additions
and
61 deletions.
There are no files selected for viewing
Empty file.
32 changes: 32 additions & 0 deletions
32
integration_tests/test_suites/daemon-test-suite/dagster_dev_command_tests/repo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from dagster import DefaultSensorStatus, RunRequest, repository, sensor | ||
from dagster._legacy import pipeline, solid | ||
|
||
|
||
@solid() | ||
def foo_solid(_): | ||
pass | ||
|
||
|
||
@pipeline | ||
def foo_pipeline(): | ||
foo_solid() | ||
|
||
|
||
@pipeline | ||
def other_foo_pipeline(): | ||
foo_solid() | ||
|
||
|
||
@sensor(job_name="foo_pipeline", default_status=DefaultSensorStatus.RUNNING) | ||
def always_on_sensor(_context): | ||
return RunRequest(run_key="only_one", run_config={}, tags={}) | ||
|
||
|
||
@repository | ||
def example_repo(): | ||
return [foo_pipeline, always_on_sensor] | ||
|
||
|
||
@repository | ||
def other_example_repo(): | ||
return [other_foo_pipeline] |
108 changes: 108 additions & 0 deletions
108
...tests/test_suites/daemon-test-suite/dagster_dev_command_tests/test_dagster_dev_command.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import os | ||
import signal | ||
import subprocess | ||
import tempfile | ||
import time | ||
|
||
import requests | ||
import yaml | ||
from dagster import DagsterEventType, DagsterInstance, EventRecordsFilter | ||
from dagster._core.test_utils import environ, new_cwd | ||
from dagster._utils import find_free_port | ||
|
||
|
||
# E2E test that spins up "dagster dev", accesses dagit, | ||
# and waits for a schedule run to launch | ||
def test_dagster_dev_command_no_dagster_home(): | ||
with tempfile.TemporaryDirectory() as tempdir: | ||
with environ({"DAGSTER_HOME": ""}): | ||
with new_cwd(tempdir): | ||
dagster_yaml = { | ||
"run_coordinator": { | ||
"module": "dagster.core.run_coordinator", | ||
"class": "QueuedRunCoordinator", | ||
}, | ||
} | ||
with open(os.path.join(str(tempdir), "dagster.yaml"), "w") as config_file: | ||
yaml.dump(dagster_yaml, config_file) | ||
|
||
dagit_port = find_free_port() | ||
|
||
dev_process = subprocess.Popen( | ||
[ | ||
"dagster", | ||
"dev", | ||
"-f", | ||
os.path.join( | ||
os.path.dirname(__file__), | ||
"repo.py", | ||
), | ||
"--dagit-port", | ||
str(dagit_port), | ||
], | ||
cwd=tempdir, | ||
) | ||
|
||
start_time = time.time() | ||
while True: | ||
try: | ||
dagit_json = requests.get( | ||
f"http://localhost:{dagit_port}/dagit_info" | ||
).json() | ||
if dagit_json: | ||
break | ||
except: | ||
print("Waiting for Dagit to be ready..") | ||
|
||
if time.time() - start_time > 30: | ||
raise Exception("Timed out waiting for Dagit to serve requests") | ||
|
||
time.sleep(1) | ||
|
||
instance = None | ||
|
||
try: | ||
start_time = time.time() | ||
instance_dir = None | ||
while True: | ||
if time.time() - start_time > 30: | ||
raise Exception("Timed out waiting for instance files to exist") | ||
subfolders = [ | ||
name | ||
for name in os.listdir(tempdir) | ||
if name.startswith("tmp") | ||
and os.path.exists(os.path.join(tempdir, name, "history")) | ||
] | ||
|
||
if len(subfolders): | ||
assert len(subfolders) == 1 | ||
instance_dir = os.path.join(str(tempdir), subfolders[0]) | ||
break | ||
|
||
time.sleep(1) | ||
|
||
with DagsterInstance.from_config(instance_dir) as instance: | ||
start_time = time.time() | ||
while True: | ||
if ( | ||
len(instance.get_runs()) > 0 | ||
and len( | ||
instance.get_event_records( | ||
event_records_filter=EventRecordsFilter( | ||
event_type=DagsterEventType.PIPELINE_ENQUEUED | ||
) | ||
) | ||
) | ||
> 0 | ||
): | ||
# Verify the run was queued (so the dagster.yaml was applied) | ||
break | ||
|
||
if time.time() - start_time > 30: | ||
raise Exception("Timed out waiting for queued run to exist") | ||
|
||
time.sleep(1) | ||
|
||
finally: | ||
dev_process.send_signal(signal.SIGINT) | ||
dev_process.communicate() |
2 changes: 2 additions & 0 deletions
2
integration_tests/test_suites/daemon-test-suite/dagster_dev_command_tests/workspace.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
load_from: | ||
- python_file: repo.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.