将代码从.bat文件放入Dag文件apache气流中

问题描述 投票:0回答:1

我是BI的新手,我需要一些帮助,我正在使用Windows Jobscheduler来执行任务,但有时会出错,因此我正转向apache airflow,我已经有一个执行的bat文件,但我想使用它在apache airflow dags中,这是我的文件bat代码

cd / d D:\ EXMOOV \ Scripts

调用RunDTS.bat EXMOOV Js_002_MOOV_AIR

我想将其放入dag文件代码中以执行它,所以我以Dag代码为例,尝试将其放入文件中,以使该文件变得不可读并且apache airflow无法读取它,这是我的尝试:

from datetime import timedelta

from airflow import DAG

from airflow.operators.bash_operator import BashOperator
from airflow.utils.dates import days_ago


default_args = {
    'owner': 'Brahim',
    'depends_on_past': False,
    'start_date': days_ago(2),
    'email': ['[email protected]'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=2),

}
dag = DAG(
    'My_first_test_code',
    default_args=default_args,
    description='A simple tutorial DAG',
    schedule_interval=timedelta(days=1),
)


t1 = BashOperator(
    task_id='print_date',
    bash_command='date',
    dag=dag,
)

cd /d D:\EXMOOV\Scripts


call RunDTS.bat EXMOOV Js_002_MOOV_AIR


    t2 = BashOperator(
        task_id='sleep',
        depends_on_past=False,
        bash_command='sleep 5',
        retries=3,
        dag=dag,
    )
    dag.doc_md = __doc__

t1.doc_md = """\

templated_command = """
{% for i in range(5) %}
    echo "{{ ds }}"
    echo "{{ macros.ds_add(ds, 7)}}"
    echo "{{ params.my_param }}"
{% endfor %}
"""

t3 = BashOperator(
    task_id='templated',
    depends_on_past=False,
    bash_command=templated_command,
    params={'my_param': 'Parameter I passed in'},
    dag=dag,
)

t1 >> [t2, t3]

[我只想要一个读取两行的dag文件,以便执行脚本以.bat格式执行的文件,该文件用于在ibm datastage中执行etl作业。

airflow scheduler directed-acyclic-graphs
1个回答
0
投票

您还没有提到您的体系结构。但是,看来您的Airflow是在Linux机器上还是在Linux的Windows子系统上已安装。无论哪种方式,我都认为您可以将Python库用于Windows远程管理(pywinrm),该库应允许您访问Windows服务器上的资源。此外,您在python脚本上运行Windows命令的语法不正确。看一下这个。!Running windows shell commands with python

© www.soinside.com 2019 - 2024. All rights reserved.