为了账号安全,请及时绑定邮箱和手机立即绑定

DAG 是否可以检测到 Airflow 中特定日期的首次运行?

DAG 是否可以检测到 Airflow 中特定日期的首次运行?

撒科打诨 2021-10-12 15:26:40
您需要使用 imshow 选项重新缩放像素:形状和范围:import numpy as npimport matplotlib.pyplot as pltshape = (112, 2182)extent = [0, 112, 0, 2182]data = np.random.random_sample(shape)plt.figure(figsize=(5, 3.5))ax = plt.subplot(111)plt.axis('off')dx = (extent[1] - extent[0]) / shape[1]dy = (extent[3] - extent[2]) / shape[0]dx_dy = dx/dyim = ax.imshow(data, extent=extent, aspect=dx_dy)plt.show()
查看完整描述

1 回答

?
缥缈止盈

TA贡献2041条经验 获得超4个赞

您可以查看以前的执行日期(prev_ds宏),并将其与当前的执行日期(比较ds在宏)BranchPythonOperator。例子:


start = DummyOperator(task_id='start_task', dag=dag)

end = DummyOperator(task_id='end_task ', dag=dag)

once = DummyOperator(task_id='once_task', dag=dag)

dummy_task_id_that_does_nothing = DummyOperator(task_id='dummy_task_id_that_does_nothing', dag=dag)


def check_if_task_already_ran(**context):

    ds = context.get('ds')

    prev_ds = context.get('prev_ds')


    print(context)

    print(ds)

    print(prev_ds)


    if prev_ds == ds:

        return 'dummy_task_id_that_does_nothing' #task_id

    else:

        return 'once_task'    # Task that would just be executed once in a day



compare_ds = BranchPythonOperator(

    task_id='compare_ds',

    provide_context=True,

    python_callable=check_if_task_already_ran,

    dag=dag)



start >> compare_ds

compare_ds >> once >> end

compare_ds >> dummy_task_id_that_does_nothing >> end


查看完整回答
反对 回复 2021-10-12
  • 1 回答
  • 0 关注
  • 148 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信