- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我关注这个example
重启调度器和网络服务器后,我得到DAG导入错误
。在 Web UI 中,最后一行详细错误消息:
airflow.exceptions.SerializationError: Failed to serialize DAG 'example_timetable_dag2': Timetable class 'AfterWorkdayTimetable' is not registered
但是如果我运行 airflow plugins
,我可以看到时间表在名称和源列表中。
如何修复这个错误?
plugins/AfterWorkdayTimetable.py
的详细信息:
from datetime import timedelta
from typing import Optional
from pendulum import Date, DateTime, Time, timezone
from airflow.plugins_manager import AirflowPlugin
from airflow.timetables.base import DagRunInfo, DataInterval, TimeRestriction, Timetable
UTC = timezone("UTC")
class AfterWorkdayTimetable(Timetable):
def infer_data_interval(self, run_after: DateTime) -> DataInterval:
weekday = run_after.weekday()
if weekday in (0, 6): # Monday and Sunday -- interval is last Friday.
days_since_friday = (run_after.weekday() - 4) % 7
delta = timedelta(days=days_since_friday)
else: # Otherwise the interval is yesterday.
delta = timedelta(days=1)
start = DateTime.combine((run_after - delta).date(), Time.min).replace(tzinfo=UTC)
return DataInterval(start=start, end=(start + timedelta(days=1)))
def next_dagrun_info(
self,
*,
last_automated_data_interval: Optional[DataInterval],
restriction: TimeRestriction,
) -> Optional[DagRunInfo]:
if last_automated_data_interval is not None: # There was a previous run on the regular schedule.
last_start = last_automated_data_interval.start
last_start_weekday = last_start.weekday()
if 0 <= last_start_weekday < 4: # Last run on Monday through Thursday -- next is tomorrow.
delta = timedelta(days=1)
else: # Last run on Friday -- skip to next Monday.
delta = timedelta(days=(7 - last_start_weekday))
next_start = DateTime.combine((last_start + delta).date(), Time.min).replace(tzinfo=UTC)
else: # This is the first ever run on the regular schedule.
next_start = restriction.earliest
if next_start is None: # No start_date. Don't schedule.
return None
if not restriction.catchup:
# If the DAG has catchup=False, today is the earliest to consider.
next_start = max(next_start, DateTime.combine(Date.today(), Time.min).replace(tzinfo=UTC))
elif next_start.time() != Time.min:
# If earliest does not fall on midnight, skip to the next day.
next_day = next_start.date() + timedelta(days=1)
next_start = DateTime.combine(next_day, Time.min).replace(tzinfo=UTC)
next_start_weekday = next_start.weekday()
if next_start_weekday in (5, 6): # If next start is in the weekend, go to next Monday.
delta = timedelta(days=(7 - next_start_weekday))
next_start = next_start + delta
if restriction.latest is not None and next_start > restriction.latest:
return None # Over the DAG's scheduled end; don't schedule.
return DagRunInfo.interval(start=next_start, end=(next_start + timedelta(days=1)))
class WorkdayTimetablePlugin(AirflowPlugin):
name = "workday_timetable_plugin"
timetables = [AfterWorkdayTimetable]
dags/test_afterwork_timetable.py
的详细信息:
import datetime
from airflow import DAG
from AfterWorkdayTimetable import AfterWorkdayTimetable
from airflow.operators.dummy import DummyOperator
with DAG(
dag_id="example_workday_timetable",
start_date=datetime.datetime(2021, 1, 1),
timetable=AfterWorkdayTimetable(),
tags=["example", "timetable"],
) as dag:
DummyOperator(task_id="run_this")
如果我运行 airflow plugins
:
name | source
==================================+==========================================
workday_timetable_plugin | $PLUGINS_FOLDER/AfterWorkdayTimetable.py
最佳答案
我有类似的问题。
要么你需要添加__init__.py
文件,或者你应该试试这个来调试你的问题:
获取所有插件管理器对象:
from airflow import plugins_manager
plugins_manager.initialize_timetables_plugins()
plugins_manager.timetable_classes
我得到了这个结果:{'quarterly.QuarterlyTimetable': <class 'quarterly.QuarterlyTimetable'>}
将您的结果与异常消息进行比较。如果timetable_classes
dictionary 有不同的插件名称,您应该更改插件文件路径。
你也可以在 DAG python 文件中尝试这个:
from AfterWorkdayTimetable import AfterWorkdayTimetable
from airflow import plugins_manager
print(plugins_manager.as_importable_string(AfterWorkdayTimetable))
这将帮助您找到 airflow 在搜索 timetable_classes
时尝试使用的名称词典。
关于airflow 2.2 时间表,总是有错误 : timetable not registered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69732193/
我正在尝试找出一种有效的结构来在 Firestore 中存储学术时间表。 我需要解决的问题: 每门类(class)都有自己的开始和结束时间 每门类(class)都有自己的周数 每门类(class)有许
我关注这个example 创建示例时间表py文件,并将其放入$Home/airflow/plugins 创建示例 dag 文件,并将其放在 $Home/airflow/dags 中 重启调度器和网络服
我正在尝试将这个不错的 javascript 插件实现到 Angular6 项目中: Timetable.js/on Github 寻找一种方法来做到这一点,我遇到了这个: How to use Ti
在ionic2项目中是否可以使用timetable.js? http://timetablejs.org/ 我尝试创建如下的 timetable.d.ts。 declare class Timetab
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 提供事实和引用来回答它. 8年前关闭。 Improve this
Here's a problem . 在解决问题之前,我不了解问题本身。具体来说:每当火车应该离开 A 或 B 时,实际上必须有一辆火车准备出发。它是什么样子的?你能给我举个例子吗?谢谢。 问题 一条
我正在为一家 vert 诊所创建一个数据库。 我在 Microsoft SQL Server Management studio 2014 中有一个 SQL 表,其关系模型(模式)如下:Schedul
我是一名优秀的程序员,十分优秀!