[英]What is the best way to execute simple user defined scripts in Python
[英]Simple way to execute tasks defined as a DAG, in python?
我正在以复杂的方式运行一系列相互依赖的任务。 我想将这些依赖关系描述为 DAG(有向无环图)并在需要时执行该图。
我一直在看气流,并写了一个虚拟脚本:
from datetime import datetime
from airflow import DAG
from airflow.operators.python import PythonOperator
def cloud_runner():
# my typical usage here would be a http call to a service (e.g. gcp cloudrun)
pass
with DAG(dag_id="my_id", schedule_interval=None, start_date=datetime.max) as dag:
first_task = PythonOperator(task_id="1", python_callable=cloud_runner)
second_task = PythonOperator(task_id="2", python_callable=cloud_runner)
second_task_bis = PythonOperator(task_id="2bis", python_callable=cloud_runner)
third_task = PythonOperator(task_id="3", python_callable=cloud_runner)
first_task >> [second_task, second_task_bis] >> third_task
运行以下命令可以完成这项工作:
airflow dags backfill my_id --start-date 2020-01-02
问题:
我的使用永远不会涉及任何类型的任何日程安排/开始日期/结束日期。 此外,我的 DAG 将从 python Flask 服务器执行。
题:
有没有办法在没有气流的情况下达到相同的结果? 或者在独立的 Python 脚本中以仅触发模式(没有所有调度部分、airflow.db 等)使用气流?
谢谢
Airflow 既是库又是应用程序。 DAG 不必按计划的方式运行。 您可以使用 API/CLI 按需触发它们。 如果 Airflow 应用程序未运行,则无法运行 DAG(计划的或手动触发的)。 Airflow 需要调度程序和元数据库才能运行。
回答您的问题 - 不可以。您必须设置并运行 Airflow 才能运行 DAG。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.