我在Windows上工作,通过Docker设置了Airflow。我在Windows中有许多python脚本,可以从Windows中的多个位置(SSH连接,Windows文件夹等)进行读写。将所有这些输入复制到我的docker映像中将需要很多工作,因此我要做的就是让Airflow像在Windows中一样运行这些脚本。
如果可能的话,这可能吗?
这是我作为DAG运行的脚本:
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
# Following are defaults which can be overridden later on
default_args = {
'owner': 'test',
'depends_on_past': False,
'start_date': datetime(2018, 11, 27),
'email': ['[email protected]'],
'email_on_failure': True,
'email_on_retry': True,
'retries': 1,
'retry_delay': timedelta(minutes=1),
}
dag = DAG('Helloworld', default_args=default_args)
###########################################################
# Here's where I want to execute my windows python script #
###########################################################
t1=PythonOperator(dag=dag,
task_id='my_task_powered_by_python',
provide_context=False,
python_callable=r"C:\Users\user\Documents\script.py")
t2 = BashOperator(
task_id='task_2',
bash_command='echo "Hello World from Task 2"',
dag=dag)
t3 = BashOperator(
task_id='task_3',
bash_command='echo "Hello World from Task 3"',
dag=dag)
t4 = BashOperator(
task_id='task_4',
bash_command='echo "Hello World from Task 4"',
dag=dag)
t2.set_upstream(t1)
t3.set_upstream(t1)
t4.set_upstream(t2)
t4.set_upstream(t3)
参考方案
您有一个传递给PythonOperator的python脚本路径,PythonOperator在寻找Python代码对象,而不是脚本文件路径。
您有两种不同的选择来完成对这些python脚本的调用。
通过Bash和BashOperator直接调用脚本
您可以像上面一样使用BashOperator直接调用python脚本。
您可以通过使用BashOperator中的以下命令,以与不使用Airflow时相同的方式调用Python脚本来完成操作
python script.py
移动脚本并使用PythonOperator
如果仅从Airflow调用这些脚本,我会考虑将它们移入Python代码库,并根据需要调用您拥有的任何入口点函数。
防爆
airflowHome/
dags/
plugins/
scripts/
__init__.py
script1.py
script2.py
现在,您将能够使用Python导入访问脚本模块中的脚本。从那里,您可以使用PythonOperator从DAG内部调用特定的函数。
在返回'Response'(Python)中传递多个参数 - python我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…
Python exchangelib在子文件夹中读取邮件 - python我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…
R'relaimpo'软件包的Python端口 - python我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。
Python ThreadPoolExecutor抑制异常 - pythonfrom concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…
如何用'-'解析字符串到节点js本地脚本? - python我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…