{"id":933,"date":"2021-04-22T12:25:00","date_gmt":"2021-04-22T04:25:00","guid":{"rendered":"https:\/\/blog.humh.cn\/?p=933"},"modified":"2021-04-22T12:25:35","modified_gmt":"2021-04-22T04:25:35","slug":"airflow%e6%ba%90%e7%a0%81%e9%98%85%e8%af%bb%e4%b8%8e%e7%90%86%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/blog.humh.cn\/?p=933","title":{"rendered":"Airflow\u6e90\u7801\u9605\u8bfb\u4e0e\u7406\u89e3"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>\u672c\u6587\u4e3b\u8981\u603b\u7ed3\u672c\u4eba\u5728\u9605\u8bfbAirflow\u6e90\u7801\u540e\u4e00\u4e9b\u7406\u89e3<\/p><\/blockquote>\n\n\n\n<h4>1\u3001airflow.models.taskinstance.py<\/h4>\n\n\n\n<p>\u5173\u4e8e<code>execution_date<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-2.png\"><img width=\"1786\" height=\"279\" class=\"wp-image-934 lazyload\" title=\"Airflow\u6e90\u7801\u9605\u8bfb\u4e0e\u7406\u89e3\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-2.png\" alt=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-2.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-2.png 1786w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-2-300x47.png 300w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-2-1024x160.png 1024w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-2-768x120.png 768w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-2-1536x240.png 1536w\" sizes=\"(max-width: 1786px) 100vw, 1786px\"><\/a><\/figure>\n\n\n\n<p>\u5982\u4e0a\u56fe\uff0c\u56e0\u4e3a\u67d0\u4e2aDAG\u4efb\u52a1\u4e2d\u4f7f\u7528xcom\uff0c\u6240\u4ee5\u5728xcom db\u4e2d\u770b\u5230\u4e86\u4e0a\u9762\u8fd9\u6761\u6570\u636e\uff0c\u60ca\u8bb6\u7684\u53d1\u73b0\u5176<code>execution_date<\/code>\u7adf\u7136\u662f\u672c\u5730\u65f6\u533a(\u5317\u4eac\/\u4e0a\u6d77 UTC+8)\u7684\u663e\u5f0f\uff0c\u800c\u4e0d\u662f\u4e00\u822c\u7684UTC\u65f6\u95f4\uff0c\u6309\u539f\u6709\u7406\u89e3\u5e94\u8be5\u662f\u201c2021-04-21T17:00:00+00:00\u201d\uff0c\u5982\u4e0b\u56feTask Instance\u4e2d<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-3.png\"><img width=\"627\" height=\"315\" class=\"wp-image-935 lazyload\" title=\"Airflow\u6e90\u7801\u9605\u8bfb\u4e0e\u7406\u89e3\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-3.png\" alt=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-3.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-3.png 627w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-3-300x151.png 300w\" sizes=\"(max-width: 627px) 100vw, 627px\"><\/a><\/figure><\/div>\n\n\n\n<p>\u5728\u6211\u7684airflow\u4e2d\uff0c\u57fa\u672c\u6240\u6709\u65f6\u95f4\u90fd\u662f\u4ee5UTC\u4e3a\u4e3b\uff0c\u6240\u4ee5\u6211\u5bf9\u4e0a\u9762\u8fd9\u79cd\u73b0\u8c61\u5f88\u7591\u60d1\uff0c\u4e3a\u4ec0\u4e48\u6267\u884c\u524d\u7684<code>execution_date<\/code>\u5c31\u662fUTC\u65f6\u533a\uff0c\u800c\u6267\u884c\u5b8c\u6210\u5c31\u53d8\u6210\u4e86\u7cfb\u7edf\u5f53\u524d\u65f6\u533a\uff08\u8fd9\u91ccUTC+8\uff09?<br>\u5728<strong>taskinstance.py<\/strong>\u7684<code>__init__<\/code>\u627e\u5230\u4e86\u7b54\u6848\uff01<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img width=\"650\" height=\"290\" class=\"wp-image-936 lazyload\" title=\"Airflow\u6e90\u7801\u9605\u8bfb\u4e0e\u7406\u89e3\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-4.png\" alt=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-4.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-4.png 650w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-4-300x134.png 300w\" sizes=\"(max-width: 650px) 100vw, 650px\"><\/figure><\/div>\n\n\n\n<p>\u5176\u4e2d\uff0c\u65e0\u8bba<code>task.has_dag<\/code>\u662f\u5426true\uff0c\u6700\u7ec8\u90fd\u4f1a\u88abconvert_to_utc\u8f6c\u6362\u4e3aUTC\u65f6\u95f4\uff0c\u8fd9\u4e5f\u5c31\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u5728Task Instance\u4e2d\u770b\u5230<code>execution_date<\/code>\u53d8\u91cf\u503c\u4e3aUTC\u65f6\u95f4<\/p>\n\n\n\n<p><strong>\u8bf4\u660e<\/strong>\uff1a<\/p>\n\n\n\n<ul><li><code>task.has_dag<\/code>\u662f\u5224\u65adOperator\u662f\u5426\u5df2\u5206\u914dDAG\u3002<\/li><li><code>timezone.make_aware<\/code>\u65e0\u8bba\u4f20\u5165<code>task.dag.timezone<\/code>\u8fd8\u662f\u4e0d\u4f20\uff0c\u5728\u8fd9\u91cc\u90fd\u662f\u4e00\u6837\u7684\uff0c\u56e0\u4e3a<code>task.dag.timezone<\/code>\u548c\u4e0d\u4f20\u7684\u60c5\u51b5\uff0c\u6700\u7ec8\u65f6\u533a\u90fd\u662f\u5bf9\u5e94<code>settings.TIMEZONE<\/code>\uff0c\u800c\u8fd9\u4e2a\u53d8\u91cf\u4e5f\u662f\u53d6\u5f97airflow\u7684\u914d\u7f6e\u9879\uff0c\u5982\u4e0b\u56fe\uff0c\u56e0\u4e3a\u201cdefault_timezone\u201d\u4e00\u822c\u4f1a\u914d\u7f6e\u6210\u548c\u7cfb\u7edf\u65f6\u533a\u4e00\u81f4\uff0c\u5c31\u7b97\u4e0d\u914d\uff0c\u9ed8\u8ba4\u4e5f\u662f\u53d6\u7cfb\u7edf\u65f6\u533a\uff0c\u5982UTC+8\u3002\u6240\u4ee5\u8fd9\u91cc\uff0c\u65e0\u8bba<code>task.has_dag<\/code>\u7ed3\u679c\u662f\u5565\uff0cif else\u6267\u884c\u540e\u7684<code>execution_date<\/code>\u662f\u4e00\u6837\u7684\u3002<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-5.png\"><img width=\"442\" height=\"225\" class=\"wp-image-937 lazyload\" title=\"Airflow\u6e90\u7801\u9605\u8bfb\u4e0e\u7406\u89e3\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-5.png\" alt=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-5.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-5.png 442w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-5-300x153.png 300w\" sizes=\"(max-width: 442px) 100vw, 442px\"><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-6.png\"><img width=\"681\" height=\"291\" class=\"wp-image-938 lazyload\" title=\"Airflow\u6e90\u7801\u9605\u8bfb\u4e0e\u7406\u89e3\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-6.png\" alt=\"https:\/\/file.blog.humh.cn\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-6.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-6.png 681w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2021\/04\/d2b5ca33bd970f64a6301fa75ae2eb22-6-300x128.png 300w\" sizes=\"(max-width: 681px) 100vw, 681px\"><\/a><figcaption>airflow webUI\u4e2d\u7684\u201cAdmin\/Configurations\u201d\u53ef\u4ee5\u67e5\u770b\u914d\u7f6e<\/figcaption><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5f85\u7ee7\u7eed\u7406\u89e3\uff0c\u8865\u5145\u3002\u3002\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u603b\u7ed3\u672c\u4eba\u5728\u9605\u8bfbAirflow\u6e90\u7801\u540e\u4e00\u4e9b\u7406\u89e3 1\u3001airflow.models.taskinstance [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":939,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[117,65],"_links":{"self":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/933"}],"collection":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=933"}],"version-history":[{"count":2,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/933\/revisions"}],"predecessor-version":[{"id":941,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/933\/revisions\/941"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/media\/939"}],"wp:attachment":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}