{"id":3095,"date":"2018-01-01T22:04:18","date_gmt":"2018-01-01T21:04:18","guid":{"rendered":"https:\/\/twentyzen.com\/blog\/faq-items\/start-mautic-cron-jobs-in-sequence\/"},"modified":"2025-02-02T21:31:48","modified_gmt":"2025-02-02T20:31:48","slug":"start-mautic-cron-jobs-in-sequence","status":"publish","type":"avada_faq","link":"https:\/\/twentyzen.com\/en\/think\/faq-items\/start-mautic-cron-jobs-in-sequence\/","title":{"rendered":"Start Mautic cron jobs in sequence"},"content":{"rendered":"<div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1248px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:0px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-1\"><p><strong>Update:<\/strong> The complete setup can now be found as a Github project at: <a href=\"https:\/\/github.com\/twentyZen\/mautic-cronjobs\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/twentyZen\/mautic-cronjobs<\/a><\/p>\n<\/div><div class=\"fusion-separator fusion-full-width-sep\" style=\"align-self: center;margin-left: auto;margin-right: auto;width:100%;\"><div class=\"fusion-separator-border sep-single sep-solid\" style=\"--awb-height:20px;--awb-amount:20px;border-color:#e0dede;border-top-width:1px;\"><\/div><\/div><div class=\"fusion-text fusion-text-2\"><p>In the <a title=\"\" href=\"https:\/\/mautic.org\/docs\/en\/setup\/cron_jobs.html\" target=\"_blank\" rel=\"noopener\">Mautic documentation for Cron Jobs<\/a> it is pointed out that the three most important Cron Jobs should be started one after the other. However, in our opinion it is not sufficient to simply start them one after the other. The unknown is the runtime of a cron job. Especially if there are already many contacts in the Mautic database and new segments are created dynamically, it can take longer.<\/p>\n<h2>Solution 1 &#8211; Cron jobs are called via shell file in series<\/h2>\n<p>Our suggested solution: We pack the cron jobs into an executable shell file in which they are actually called one after the other. This file is then started regularly by a cron job.<\/p>\n<ol>\n<li>Create a file, e.g. with the name &#8220;cronjob.sh&#8221; in the \/app directory in the Mautic installation,<\/li>\n<li>Write the three cronjobs into it. The syntax looks something like this:<br \/>\n#!\/bin\/sh<br \/>\n\/PATHTOPHP\/php \/PATHTOMAUTIC\/app\/console mautic:segments:update<br \/>\n\/PATHTOPHP\/php \/PATHTOMAUTIC\/app\/console mautic:campaigns:rebuild<br \/>\n\/PATHTOPHP\/php \/PATHTOMAUTIC\/app\/console mautic:campaigns:trigger<\/li>\n<li>Customize PATHTOPHP and PATHTOMAUTIC to your own installation without forgetting<\/li>\n<li>Create a cron job for running cronjob.sh<\/li>\n<\/ol>\n<p>Attention! Of course the Cron jobs must not be started too fast! Of course the cron jobs must not be started too fast one after the other. This is to prevent that cronjob.sh is called before the last run was finished. Start e.g. every 5 minutes &#8211; the notation for this is *\/5 * * * * * (more here: <a href=\"https:\/\/crontab.guru\/\">https:\/\/crontab.guru\/<\/a>)<\/p>\n<h2>Solution 2 &#8211; Cron Job calls Mautic commands in sequence<\/h2>\n<p>Meanwhile we are using a second variant, which is much faster to create. We chain all Mautic tasks via &#8220;&amp;&amp;;&#8221; directly when setting the cron jobs (sometimes also called &#8220;planned tasks&#8221;). This works differently from hoster to hoster, often via an administration interface.<\/p>\n<p>The command that is then called looks something like this:<\/p>\n<p>\/PATHTOPHP\/php \/PATHTOMAUTIC\/app\/console mautic:segments:update &amp;&amp; \/PATHTOPHP\/php \/PATHTOMAUTIC\/app\/console mautic:campaigns:rebuild &amp; \/PATHTOPHP\/php \/PATHTOMAUTIC\/app\/console mautic:campaigns:trigger<\/p>\n<p>In this variant the risk of parallel running cron jobs is lower, because the system &#8220;sees&#8221; the running cron job in this case. In variant 1 a shell script is simply started and the cron job is immediately completed successfully.<\/p>\n<\/div><div class=\"fusion-content-boxes content-boxes columns row fusion-columns-1 fusion-columns-total-1 fusion-content-boxes-1 content-boxes-icon-with-title content-left\" style=\"--awb-backgroundcolor:#fbded9;--awb-body-color:#1e3748;--awb-title-color:#1e3748;--awb-hover-accent-color:#e7344c;--awb-circle-hover-accent-color:#e7344c;--awb-item-margin-bottom:40px;\" data-animationOffset=\"top-into-view\"><div style=\"--awb-backgroundcolor:#fbded9;\" class=\"fusion-column content-box-column content-box-column content-box-column-1 col-lg-12 col-md-12 col-sm-12 fusion-content-box-hover content-box-column-last content-box-column-last-in-row\"><div class=\"col content-box-wrapper content-wrapper-background link-area-link-icon link-type-text content-icon-wrapper-yes icon-hover-animation-fade\" data-animationOffset=\"top-into-view\"><div class=\"heading heading-with-icon icon-left\"><a class=\"heading-link\" style=\"float:left;\" href=\"https:\/\/twentyzen.com\/en\/marketing-automation\/\" target=\"_self\"><div class=\"icon\"><span style=\"height:62px;width:62px;line-height:32px;border-color:rgba(255,255,255,0);border-width:1px;border-style:solid;background-color:#e7344c;box-sizing:content-box;border-radius:50%;\"><i style=\"border-color:#e7344c;border-width:1px;background-color:#e7344c;box-sizing:content-box;height:60px;width:60px;line-height:60px;border-radius:50%;position:relative;top:auto;left:auto;margin:0;border-radius:50%;font-size:30px;\" aria-hidden=\"true\" class=\"fontawesome-icon fa-newspaper fas circle-yes\"><\/i><\/span><\/div><h2 class=\"content-box-heading fusion-responsive-typography-calculated\" style=\"--h2_typography-font-size:24px;--fontSize:24;line-height:1.2;\">twentyZEN GmbH is Mautic Partner<\/h2><\/a><\/div><div class=\"fusion-clearfix\"><\/div><div class=\"content-container\">If you need professional support, we offer Mautic support and assistance in developing your marketing automation strategy. Alternatively to your own installation, you can also use the commercial Mautic Cloud. So you can concentrate fully on your strategy. You can start for free.<\/div><div class=\"fusion-clearfix\"><\/div><a class=\" fusion-read-more\" style=\"float:left;\" href=\"https:\/\/twentyzen.com\/en\/marketing-automation\/\" target=\"_self\">Mautic Partner twentyZEN<\/a><div class=\"fusion-clearfix\"><\/div><\/div><\/div><div class=\"fusion-clearfix\"><\/div><\/div><\/div><\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":3,"featured_media":4097,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"faq_category":[279],"class_list":["post-3095","avada_faq","type-avada_faq","status-publish","format-standard","has-post-thumbnail","hentry","faq_category-mautic-faq"],"acf":{"autor":"","antwort":"","portrait":"","autorlink":[""],"url":"","textauszug":"","veranstaltungsinfo":""},"_links":{"self":[{"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/avada_faq\/3095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/avada_faq"}],"about":[{"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/types\/avada_faq"}],"author":[{"embeddable":true,"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/comments?post=3095"}],"version-history":[{"count":3,"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/avada_faq\/3095\/revisions"}],"predecessor-version":[{"id":24317,"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/avada_faq\/3095\/revisions\/24317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/media\/4097"}],"wp:attachment":[{"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/media?parent=3095"}],"wp:term":[{"taxonomy":"faq_category","embeddable":true,"href":"https:\/\/twentyzen.com\/en\/wp-json\/wp\/v2\/faq_category?post=3095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}