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

您需要使用 imshow 选项重新缩放像素:形状和范围:


import numpy as np

import matplotlib.pyplot as plt


shape = (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/dy


im = ax.imshow(data, extent=extent, aspect=dx_dy)

plt.show()


撒科打诨
浏览 149回答 1
1回答

缥缈止盈

您可以查看以前的执行日期(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 daycompare_ds = BranchPythonOperator(    task_id='compare_ds',    provide_context=True,    python_callable=check_if_task_already_ran,    dag=dag)start >> compare_dscompare_ds >> once >> endcompare_ds >> dummy_task_id_that_does_nothing >> end
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python