当前位置:网站首页>AirFlow的Scheduling的start_date解释
AirFlow的Scheduling的start_date解释
2022-07-21 16:47:00 【善皮之】
Airflow的scheduling的start_date和schedular_interval
问题出现
Airflow
是一个定时调度框架,最近公司需要用到airflow
进行对脚本程序的调度。所以公司搭建了一个Airflow
的平台,现在有一个任务需要在每天的18点02分执行,那么我们怎么做呢?
我们编辑了一个Airflow
的python
文档,(具体的代码就不放出来了)里面的内容大致如下:
在这个图里面,关注两个变量名称
* start_date
* schedule_intervel
现在需求是从2020-06-18 18:02:00
开始程序的第一次执行,此后,程序将会在每一天的18:02:00
这个时间点执行。
在实现这个需求之前,我们先做了一个针对Airflow
的测试,测试的目的是想要验证一下Airflow
能否正常的去执行。
测试过程
&emsp:&emsp:在开始之前,我们准备了一个shell
脚本内容如下:
date >> mydate.txt
在北京时间为:2020-06-18 15:16:00
的时刻下(当前时间2020-06-18 15:14:00
),我们想要让这个shell
脚本第一次执行,并且每五分钟执行一次。
当时的参数如下:start_date
设置为:datetime(2020,6,18,15,16)
scheduler_interval
设置为:*/5 * * *
当时的想法是:程序在start_date
即2020年6月18日的15点16分,进行第一次的任务调度。即:2020-06-18 15:16:00
的时候进行第一次的任务调度。因为设置了调度周期scheduler_interval
所以,程序会每五分钟调度一次,即在2020-06-18 15:21:00
的时候开始进行第二次调度。之后每五分钟执行一次。
注意
上面的执行逻辑是错误的。在我们实际的测试之后发现,该程序第一次的运行时间,为2020-06-18 15:25:00
这与上述我期望的第一次的执行时间(2020-06-18 15:16:00
)不同。所以问题出现了,start_date
设置的时间不是程序第一次启动的时间。
探究过程
查阅了官方的文档,并且经过一系列的测试。得出了结论:
- 第一次运行的时间并不能用
start_date
来理解,应该用后面的scheduler_interval
来理解scheduler_interval
用的是cron
表达式,在我的测试例子中,cron
表达式为:*/5 * * *
表达的是每5分钟运行一次。所以,在2020年6月18日15点的时间区间里面,程序执行的时间点为:
而不是期望的时间表(起个临时名字) 2020-06-18 15:00:00 2020-06-18 15:05:00 2020-06-18 15:10:00 2020-06-18 15:15:00 2020-06-18 15:20:00 2020-06-18 15:25:00 2020-06-18 15:30:00 . . . 2020-06-18 15:50:00 2020-06-18 15:55:00
start_date
+n *scheduler_inveral
(n ∈N)
当时我们处于例如 start_date = 2020-06-18 15:16:00 第二次执行时间:2020-06-18 15:21:00 第三次执行时间:2020-06-18 15:26:00 (然而事实不是这样的,哦豁,摊手,上面的时间点就没在上面的时间表里面)
2020-06-18 15:14:00
这个时间点,设置的start_date
为2020-06-18 15:16:00
,可以看到离2020-06-18 15:16:00
这个时间点最近的执行时间是2020-06-18 15:20:00
,然而第一次执行的时间点是2020-06-18 15:25:00
,(下面解释为啥) Airflow
调度程序的时候,程序第一次运行的时间为:start_date
加上一个周期的scheduler_interval
当设置的start_date
为2020-06-18 15:16:00
加上一个周期时间5分钟,时间变为2020-06-18 15:21:00
,时间表
, 在未来离这个时间最近时间点为:2020-06-18 15:25:00
,所以我测试的第一次执行的时间为:2020-06-18 15:25:00
接下来我们测试另外一个脚本:
当前现实时间:2020-06-18 15:44:00
start_date:2020-06-18 15:46:00
schedular_interval:*/2 * * * *
这么做的目的是因为schedular_interval为2分钟执行一次,start_date刚好卡在这个点上,能否在这个start_date点执行,即2020-06-18 15:46:00
进行程序的第一次执行。
然而它第一次的执行时间为:2020-06-18 15:48:00
,也印证了Airflow
调度程序的时候第一次执行的时间为:start_date
+schedular_interval
结论
Airflow
的官网例子中,start_date
有很多都设置为了days_ago(2)
(适用于调度周期在天以内的,时间的周期调度主要靠cron
表达来判断,所以cron
表达式很重要。另外的话,记住程序的第一次调度时间为start_date
+schedular_interval
。
如果大佬们有啥其他的见解,请在下方留言。共同学习,共同进步,谢谢。
边栏推荐
- 移动端测试用例的编写
- SSM项目完整源码[通俗易懂]
- 支付宝统一支付回调接口(适用于H5、PC、APP)
- "Everything is interconnected, enabling thousands of industries", the 2022 open atom global open source summit openatom openharmony sub forum is about to open
- 官网收藏...
- 活动报名:如何零基础快速上手开源的 Tapdata Live Data Platform?
- R language uses oneway The test function performs one-way ANOVA. If there is the same variance between groups, set the var.equal parameter to true to obtain a more relaxed test
- 无线充电原理与QI协议详解[通俗易懂]
- 微信小程序 wx.request的简单封装
- Mutual certification of product compatibility between tapdata and Youxuan database
猜你喜欢
wallys/new product/DR7915/MT7915+MT7975/WiFi6 MiniPCIe Module 2T2R
Generating function (linear recursive relationship, generating function concept and formula derivation, violent calculation) 4000 word detailed analysis, with examples
DistSQL 深度解析:打造动态化的分布式数据库
lombok的注解@Accessors
wallys/new product/DR7915/MT7915+MT7975/WiFi6 MiniPCIe Module 2T2R
Interface document evolution atlas, some ancient interface document tools, you may not have used them
Geek planet ByteDance one stop data governance solution and platform architecture
WebSockets 和 Server-Sent Events
Property dataSource is required 异常处理 [IDEA]
JMeter --- FTP performance test
随机推荐
滴滴收80亿罚单 数据安全板块大涨 奇安信午盘涨5.6%
There is garbled code in the JSON string generated by rapidjson
cmake使用boost静态库,错误提示找Could NOT find Boost (missing: system thread filesystem
使用OpenCv+Arduino实现挂机自动打怪
一个公用的dao类和util
[binary tree] verify binary tree
【案例设计】事件分发器 — 实现跨类的事件响应思路分享与实现
R language uses the ggarrange function of ggpubr package to combine multiple images, and uses the ggexport function to save the visual image in TIFF format (width parameter specifies width, height par
移动端测试用例的编写
R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、构建没有截距项的回归模型(模型不包含截距)
活动报名:如何零基础快速上手开源的 Tapdata Live Data Platform?
Advanced architects, 16 common principles of microservice design and Governance
Unity skframework framework (I), audio manager
Detailed explanation of the application of FFT fast Fourier transform in string matching [attached template, example] 5000 word detailed explanation
生成函数(线性递推关系,生成函数概念与公式推导,暴力计算)四千字详细解析,附例题
西门子博图安装期间反复重启的问题处理
ROS机械臂 Movelt 学习笔记1 | 基础准备
微信支付Native(一)准备和相关知识
看完这个,还不会DVMA,请你吃瓜
R language ggplot2 visualization: use the ggarrange function of ggpubr package to combine multiple images, and use the nrow parameter to specify the number of rows in the combined image