- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Apache Airflow 1.10+引入了对 DST 感知的原生支持 timezones .
这让我认为(也许是错误的)应该可以在同一个 Airflow 调度程序上创建 2 个 DAG,这些调度程序是这样安排的:
Pacific/Auckland
开始时间America/New_York
开始时间default_timezone
到系统时区。然后我尝试像这样安排 DAG:
DAG('NZ_SOD',
description='New Zealand Start of Day',
start_date=datetime(2018, 12, 11, 06, 00, tzinfo=pendulum.timezone('Pacific/Auckland')),
catchup=False)
DAG('NAM_EOD',
description='North Americas End of Day',
start_date=datetime(2018, 12, 11, 21, 00, tzinfo=pendulum.timezone('America/New_York')),
catchup=False)
start_date
的日期时间对象的“时间”部分在 Apache Airflow 中未明确考虑并会产生意外行为。
最佳答案
答案是肯定的,cron 计划支持在 DST 感知时区运行 DAG。
但是有一些警告,所以我不得不假设 Airflow 的维护者没有将此作为受支持的用例。首先是documentation ,截至撰写本文时,明确为 错了当它指出:
Cron schedules
In case you set a cron schedule, Airflow assumes you will always want to run at the exact same time. It will then ignore day light savings time. Thus, if you have a schedule that says run at end of interval every day at 08:00 GMT+1 it will always run end of interval 08:00 GMT+1, regardless if day light savings time is in place.
import pendulum
from airflow import DAG
from datetime import timedelta
# Set-up DAG
test_dag = DAG(
dag_id='foo',
start_date=pendulum.datetime(year=2019, month=4, day=4, tz='Pacific/Auckland'),
schedule_interval='00 03 * * *',
catchup=False
)
# Check initial schedule
execution_date = test_dag.start_date
for _ in range(7):
next_execution_date = test_dag.following_schedule(execution_date)
if next_execution_date <= execution_date:
execution_date = test_dag.following_schedule(execution_date + timedelta(hours=2))
else:
execution_date = next_execution_date
print('Execution Date:', execution_date)
这给了我们 7 天的时间让新西兰体验 DST:
Execution Date: 2019-04-03 14:00:00+00:00
Execution Date: 2019-04-04 14:00:00+00:00
Execution Date: 2019-04-05 14:00:00+00:00
Execution Date: 2019-04-06 14:00:00+00:00
Execution Date: 2019-04-07 15:00:00+00:00
Execution Date: 2019-04-08 15:00:00+00:00
Execution Date: 2019-04-09 15:00:00+00:00
正如我们所看到的,使用 cron 时间表观察到 DST,如果您编辑我的代码以删除 cron 时间表,您可以进一步看到 DST 是
不是 观测到的。
follow_schedule
中没有说明。逻辑。
provide_context=True
为作业提供的变量。如果 DAG 的本地执行日期与 UTC 执行日期不同,对于 Python 可调用对象将是错误的。这可以在
TaskInstance.get_template_context 中观察到。使用
self.execution_date
无需将其修改为本地时间。我们可以在
TaskInstance.__init__ 中看到那
self.execution_date
转换为 UTC。
local_cal_date
的变量。通过执行@dlamblin 的建议并使用
convert
Pendulum 的方法。编辑此代码以满足您的特定需求(我实际上在所有 Python 可调用对象的包装器中使用它,以便它们都接收
local_cal_date
):
import datetime
def foo(*args, dag, execution_date, **kwargs):
# Derive local execution datetime from dag and execution_date that
# airflow passes to python callables where provide_context is set to True
airflow_timezone = dag.timezone
local_execution_datetime = airflow_timezone.convert(execution_date)
# I then add 1 day to make it the calendar day
# and not the execution date which Airflow provides
local_cal_datetime = local_execution_datetime + datetime.timedelta(days=1)
更新:对于我发现的模板化字符串,最好的方法是创建自定义运算符,在呈现模板之前将自定义变量注入(inject)到上下文中。我发现使用自定义宏的问题是
don't expand other macros automatically ,这意味着您必须做很多额外的工作才能以有用的方式呈现它们。因此,在自定义运算符模块中,我与此代码有些相似:
# Standard Library
import datetime
# Third Party Libraries
import airflow.operators.email_operator
import airflow.operators.python_operator
import airflow.operators.bash_operator
class CustomTemplateVarsMixin:
def render_template(self, attr, content, context):
# Do Calculations
airflow_execution_datetime = context['execution_date']
airflow_timezone = context['dag'].timezone
local_execution_datetime = airflow_timezone.convert(airflow_execution_datetime)
local_cal_datetime = local_execution_datetime + datetime.timedelta(days=1)
# Add to contexts
context['local_cal_datetime'] = local_cal_datetime
# Run normal Method
return super().render_template(self, attr, content, context)
class BashOperator(CustomTemplateVarsMixin, airflow.operators.bash_operator.BashOperator):
pass
class EmailOperator(CustomTemplateVarsMixin, airflow.operators.email_operator.EmailOperator):
pass
class PythonOperator(CustomTemplateVarsMixin, airflow.operators.python_operator.PythonOperator):
pass
class BranchPythonOperator(CustomTemplateVarsMixin, airflow.operators.python_operator.BranchPythonOperator):
pass
关于airflow - Apache Airflow 1.10+ 调度程序是否支持在特定时间在不同的 DST 感知时区运行 2 个 DAG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53783626/
晚安,我正在与一些合作伙伴使用 javaFx 制作一个应用程序;我们的想法是它将在 Windows 和 Linux 中使用。我们进行了一些测试,发现应用程序在两种操作系统中的显示有所不同。 我们正在使
我有一项服务,可通过 CreateProcessAsUser 将可执行文件启动到用户 session 中,并在 STARTUPINFO 参数中指定桌面。它运行良好。 我的可执行文件没有显示出来,也没有
当每个文件写入集群时,HDFS 会创建一个复制管道。假设有两个 Rack 1 和 5。根据 Rack 感知,第一个 block 将被保存到 Rack 1,其他两个复制 block 将被插入 Rack
我正在做一个 Django 项目,我对时区感到困惑。 我有一个事件对象,它有 publish_start 和 publish_end 日期。 控制台输出示例; campaingObject.publi
我在下面有一个函数,它通过将字体 (.ttf) 复制到 Windows 字体文件夹然后触发 WM_FONTCHANGE 消息将其安装到 Windows 中。但是,该字体不会立即在 Windows 资源
是否有类似 grep 的 Unix/Linux 命令行工具可以理解由 log4j 或 logback 打印的日志文件中的 Java 堆栈跟踪?该工具应该理解堆栈跟踪由多行组成。 典型的用例是在查看存储
每次我在我的 SCM 中看到诸如导入或方法签名更改(例如变量的重命名)之类的冲突时,我想知道是否有类似语言感知的 diff/merge 方法可以处理更烦人的小更改发生在共享项目上。有什么东西可以在 U
我使用 astyanax 连接池定义如下: ipSeeds = "LOAD_BALANCER_HOST:9160"; conPool.setSeeds(ipSeeds) .setDiscoveryTy
据我所知,OCaml 中的字符串只是简单的字节序列。他们没有编码的概念。 这对于大多数用途来说都很好。但是,标准库的某些部分对以单字节字符集编码的字符串做出了假设,例如 printf 的对齐功能: #
据我所知,OCaml 中的字符串只是简单的字节序列。他们没有编码的概念。 这对于大多数用途来说都很好。但是,标准库的某些部分对以单字节字符集编码的字符串做出了假设,例如 printf 的对齐功能: #
我正在使用 this enhanced version of WebClient登录网站: public class CookieAwareWebClient : WebClient {
我正在尝试将 Awareness API 集成到一个新项目中,但我遇到了一条错误消息:ACL_ACCESS_DENIED 状态代码:7503。 我也在其他项目中集成了 Awareness API,但上
有什么方法可以定义一个 spring bean,当 session 中的数据发生变化时,它会得到通知? 如果可能的话,我还想知道纯 Java 解决方案。我想要的只是当我在 httpsession 中添
有没有方便有效的方式以 NUMA 感知方式使用 cpp 标准容器 API? 我想在 cpp 环境中执行 OpenMP 并行稀疏矩阵 vector 乘法。要分配和初始化与 NUMA 域有关的 vecto
我正在创建一个程序,它使用 SetWindowPos() 从另一个进程移动/调整窗口大小。我自己的程序是 PROCESS_PER_MONITOR_DPI_AWARE。其他程序可以是 PROCESS_D
我一直在研究许多 JDBC 连接池,但我有一个特定的要求,即池需要是 JTA 感知的,这给我留下了 Apache DBCP 和 OW2 XAPool 的简短列表。我查看的其他池(c3p0、Proxoo
我有一个 php 脚本,可以在服务器上发出一系列请求。第一个请求将是登录请求。 问题是 file_get_contents 似乎每次都创建一个新 session ,那么我怎样才能让它感知 sessio
我有一个整数,表示 unix 纪元之后的微秒数。 (格林威治标准时间) 如何使用 astype 将 1349863207154117 转换为 pandas.Timestamp("2012-10-10T
我有一个 Web 服务,我正在尝试将变量 Autowiring 到其中。这是类(class): package com.xetius.isales.pr7.service; import java.u
再会! 我已经在 WPF 应用程序上工作了一段时间(作为一种学习体验,哦,天哪,这是一种学习体验),它终于可以发布了。发布意味着将其安装在我的 HTPC 上,用于浏览我的电影收藏。 我在运行 1920
我是一名优秀的程序员,十分优秀!