匕首主进程的工作目录是否与调度程序进程不同

  • 本文关键字:进程 是否 调度程序 工作 dagster
  • 更新时间 :
  • 英文 :


我在从 dagster 代码(设置,而不是管道(加载文件时遇到问题。假设我有以下项目结构:

pipelines
-app/
--environments
----schedules.yaml
--repository.py
--repository.yaml

当我在项目文件夹($cd project && dagit -y app/repository.yaml(内运行 dagit 时,该文件夹将成为工作目录,在repository.py内我可以加载一个文件,知道根是project

# repository.py
with open('app/evironments/schedules.yaml', 'r'):
# do something with the file

但是,如果我设置了计划,项目中的管道将不会运行。检查 cron 日志似乎open行抛出一个找不到文件异常。我想知道这是否是因为执行 cron 时工作目录不同而发生这种情况。

对于上下文,我正在加载一个配置文件,其中包含每个管道的 cron_schedules 参数。另外,在我的情况下,这是堆栈跟踪的尾部:

File "/home/user/.local/share/virtualenvs/pipelines-mfP13m0c/lib/python3.8/site-packages/dagster/core/definitions/handle.py", line 190, in from_yaml
return LoaderEntrypoint.from_file_target(
File "/home/user/.local/share/virtualenvs/pipelines-mfP13m0c/lib/python3.8/site-packages/dagster/core/definitions/handle.py", line 161, in from_file_target
module = import_module_from_path(module_name, os.path.abspath(python_file))
File "/home/user/.local/share/virtualenvs/pipelines-mfP13m0c/lib/python3.8/site-packages/dagster/seven/__init__.py", line 75, in import_module_from_path
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/user/pipelines/app/repository.py", line 28, in <module>
schedule_builder = ScheduleBuilder(settings.CRON_PRESET, settings.ENV_DICT)
File "/home/user/pipelines/app/schedules.py", line 12, in __init__
self.cron_schedules = self._load_schedules_yaml()
File "/home/user/pipelines/app/schedules.py", line 16, in _load_schedules_yaml
with open(path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'app/environments/schedules.yaml'

您可以使用文件的绝对路径打开文件,以便正确打开。

from dagster.utils import file_relative_path
with open(file_relative_path(__file__, './environments/schedules.yaml'), 'r'):
# do something with the file

所有file_relative_path都只是执行以下操作,因此如果您愿意,可以直接调用os.path方法:

def file_relative_path(dunderfile, relative_path):
os.path.join(os.path.dirname(dunderfile), relative_path)

最新更新