{"id":10728,"date":"2022-11-25T14:18:31","date_gmt":"2022-11-25T06:18:31","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=10728"},"modified":"2022-11-25T15:35:22","modified_gmt":"2022-11-25T07:35:22","slug":"cron","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2022\/11\/25\/cron\/","title":{"rendered":"go\u8bed\u8a00\u4e4b\u5b9a\u65f6\u4efb\u52a1cron"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">golang\u4e5f\u53ef\u4ee5\u6267\u884c\u5b9a\u65f6\u4efb\u52a1\uff0c\u9700\u8981\u501f\u52a9\u7b2c\u4e09\u65b9\u5305\uff0c\u5305\u540d\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>github.com\/robfig\/cron<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">cron\u5b9a\u65f6\u4efb\u52a1\u8868\u8fbe\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"224\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/3-9.png\" alt=\"\" class=\"wp-image-10735\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/3-9.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/3-9-300x95.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/3-9-600x190.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0elinux\u7684crontab\u5927\u81f4\u76f8\u540c\uff0c\u4f46\u662f\u6bd4crontab\u591a\u4e86\u7b2c\u4e00\u4e2a\u53c2\u6570second\uff0c\u8868\u793a\u79d2, crontab\u7684\u5b9a\u65f6\u4efb\u52a1\u5206\u4e3a&#8221;\u5206\u3001\u65f6\u3001\u65e5\u3001\u6708\u3001\u5468&#8221;\uff0ccron\u7684\u5b9a\u65f6\u4efb\u52a1\u5206\u4e3a&#8221;\u79d2\u3001\u5206\u3001\u65f6\u3001\u65e5\u3001\u6708\u3001\u5468&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5339\u914d\u7b26\u53f7\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u661f\u53f7(*)\uff1a\u8868\u793a cron \u8868\u8fbe\u5f0f\u80fd\u5339\u914d\u8be5\u5b57\u6bb5\u7684\u6240\u6709\u503c<\/li><li>\u659c\u7ebf(\/)\uff1a\u8868\u793a\u589e\u957f\u95f4\u9694\uff0c\u610f\u601d\u662f\u6bcf\u9694\u591a\u957f\u65f6\u95f4\u6267\u884c\u4e00\u6b21<\/li><li>\u9017\u53f7(,)\uff1a\u679a\u4e3e\u503c<\/li><li>\u8fde\u5b57\u597d(-)\uff1a\u8868\u793a\u4e00\u4e2a\u8303\u56f4<\/li><li>\u95ee\u53f7(?)\uff1a\u53ea\u80fd\u7528\u4e8e\u65e5\u548c\u5468\u7684\u4f4d\u7f6e\uff0c\u8868\u793a\u4e0d\u6307\u5b9a\u503c\uff0c\u53ef\u4ee3\u66ff*<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\"*\/5 * * * * ?\"        \/\/\u6bcf\u96945s\u6307\u5b9a\u4e00\u6b21\n\"0 *\/1 * * * ?\"        \/\/\u6bcf\u96941\u5206\u949f\u6267\u884c\u4e00\u6b21\n\"0 5\/10 * * * ?\"        \/\/\u6bcf\u4e2a\u5c0f\u65f6\u7684\u7b2c5\u5206\u5f00\u59cb\u6267\u884c\uff0c\u6bcf\u969410\u5206\u949f\u6267\u884c\u4e00\u6b21\n\"0 0 22 * * ?\"         \/\/\u6bcf\u592922\u70b9\u6267\u884c\u4e00\u6b21(22\u70b90\u52060\u79d2)\n\"0 0 1 * * ?\"          \/\/\u6bcf\u5929\u51cc\u66681\u70b9\u6267\u884c\u4e00\u6b21\n\"0 0 1 1 * ?\"          \/\/\u6bcf\u4e2a\u67081\u53f7\u51cc\u66681\u70b9\u6267\u884c\u4e00\u6b21\n\"0 22,25,36 * * * ?\"   \/\/\u572822\u5206\u300125\u5206\u300126\u5206\u6267\u884c\u4e00\u6b21\n\"0 10-30\/5 * * * ?\"    \/\/\u6bcf\u4e2a\u5c0f\u65f6\u768410\u5206\u523030\u5206\u6267\u884c\uff0c\u6bcf\u96945\u5206\u6267\u884c\u4e00\u6b21\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e5f\u53ef\u4ee5\u4f7f\u7528\u9884\u5b9a\u4e49\u7684\u7b49\u5f0f\u4ee3\u66ff\u4e0a\u8ff0\u8868\u8fbe\u5f0f\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">\u8f93\u5165<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u63cf\u8ff0<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u7b49\u5f0f<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">@yearly (or @annually)<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u6bcf\u5e741\u67081\u65e5\u5348\u591c\u8dd1\u6b65\u4e00\u6b21<\/td><td class=\"has-text-align-center\" data-align=\"center\">0 0 0 1 1 *<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">@monthly<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u6bcf\u4e2a\u6708\u7b2c\u4e00\u5929\u7684\u5348\u591c\u8dd1\u4e00\u6b21<\/td><td class=\"has-text-align-center\" data-align=\"center\">0 0 0 1 * *<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">@weekly<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u6bcf\u5468\u5468\u516d\u7684\u5348\u591c\u8fd0\u884c\u4e00\u6b21<\/td><td class=\"has-text-align-center\" data-align=\"center\">0 0 0 * * 0<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">@daily (or @midnight)<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u6bcf\u5929\u5348\u591c\u8dd1\u4e00\u6b21<\/td><td class=\"has-text-align-center\" data-align=\"center\">0 0 0 * * *<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">@hourly<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u6bcf\u5c0f\u65f6\u8fd0\u884c\u4e00\u6b21<\/td><td class=\"has-text-align-center\" data-align=\"center\">0 0 * * * *<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u4e0b\u9762\u901a\u8fc7AddFunc()\u5b9e\u73b0\u4e00\u4e2a\u5355\u4efb\u52a1\u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u96945s\u6267\u884c\u4e00\u6b21\u4efb\u52a1\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"592\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/15-3.png\" alt=\"\" class=\"wp-image-10729\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/15-3.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/15-3-300x250.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/15-3-600x500.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"245\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/1-12.png\" alt=\"\" class=\"wp-image-10731\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/1-12.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/1-12-300x104.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/1-12-600x207.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u4e0b\u9762\u8868\u793a\u901a\u8fc7AddJob()\u6dfb\u52a02\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0c\u6bcf\u96943s\u548c5s\u6267\u884c\u4e00\u6b21\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"711\" height=\"747\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/5-8.png\" alt=\"\" class=\"wp-image-10741\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/5-8.png 711w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/5-8-286x300.png 286w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/5-8-571x600.png 571w\" sizes=\"auto, (max-width: 711px) 100vw, 711px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"218\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/6-7.png\" alt=\"\" class=\"wp-image-10742\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/6-7.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/6-7-300x92.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/6-7-600x184.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u770b\u51fa\uff0c\u5b9a\u65f6\u4efb\u52a11\u6bcf\u96943s\u6267\u884c\u4e00\u6b21\uff0c\u5b9a\u65f6\u4efb\u52a12\u6bcf\u96945s\u6267\u884c\u4e00\u6b21<\/p>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1aAddFunc()\u5e95\u5c42\u4e5f\u662f\u57fa\u4e8eAddJob()\u5b9e\u73b0\u7684\uff0c\u56e0\u6b64\u5982\u679c\u6267\u884c\u591a\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0c\u901a\u8fc7AddFunc()\u548cAddJob()\u90fd\u53ef\u4ee5\u7684<\/p>\n","protected":false},"excerpt":{"rendered":"<p>golang\u4e5f\u53ef\u4ee5\u6267\u884c\u5b9a\u65f6\u4efb\u52a1\uff0c\u9700\u8981\u501f\u52a9\u7b2c\u4e09\u65b9\u5305\uff0c\u5305\u540d\u5982\u4e0b\uff1a cron\u5b9a\u65f6\u4efb\u52a1\u8868\u8fbe\u5f0f\u5982\u4e0b\uff1a \u4e0elinux\u7684cr [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":10732,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,23],"tags":[],"class_list":["post-10728","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go","category-rong"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/10728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=10728"}],"version-history":[{"count":11,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/10728\/revisions"}],"predecessor-version":[{"id":10750,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/10728\/revisions\/10750"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/10732"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=10728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=10728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=10728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}