<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: John</title>
    <description>The latest articles on DEV Community by John (@john200ok).</description>
    <link>https://dev.to/john200ok</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F282834%2F2100abb0-2dd2-4c5c-8d3d-85a20ac3df4c.jpg</url>
      <title>DEV Community: John</title>
      <link>https://dev.to/john200ok</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/john200ok"/>
    <language>en</language>
    <item>
      <title>Free and Painless Cron Job Monitoring via CronMonit</title>
      <dc:creator>John</dc:creator>
      <pubDate>Sat, 30 Nov 2019 15:18:56 +0000</pubDate>
      <link>https://dev.to/john200ok/free-and-painless-cron-job-monitoring-via-cronmonit-8n9</link>
      <guid>https://dev.to/john200ok/free-and-painless-cron-job-monitoring-via-cronmonit-8n9</guid>
      <description>&lt;p&gt;If you ever lost data, money or customers because of a failing cron job that went unnoticed, you’ll know how important it is to monitor cron jobs.&lt;/p&gt;

&lt;p&gt;There are a lot of different ways to monitor a cron job. Here are a couple of examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instructing cron to always send all output and errors via email: &lt;a href="https://stackoverflow.com/questions/19451680/how-to-save-cronjob-error-to-file-and-email-it"&gt;https://stackoverflow.com/questions/19451680/how-to-save-cronjob-error-to-file-and-email-it&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instructing cron to only send an email when an error happens: &lt;a href="https://stackoverflow.com/questions/19451680/how-to-save-cronjob-error-to-file-and-email-it"&gt;https://stackoverflow.com/questions/19451680/how-to-save-cronjob-error-to-file-and-email-it&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Solution #1 above is very noisy and will bombard your email address with lots of emails especially if you have a lot of cron jobs and they frequently run. The good thing about it is you’ll know if your cron jobs actually ran or an error happened. But this is only useful if you always and immediately check the sent emails.&lt;/p&gt;

&lt;p&gt;Solution #2 above is better but it won’t notify you on some scenarios like cron is not running at all or if the server is down for some reason.&lt;/p&gt;

&lt;p&gt;Another downside by using the solutions above is you’ll need to make sure that your server is able to send emails and make sure the emails doesn’t get marked as spam: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://serverfault.com/questions/48428/how-to-send-emails-and-avoid-them-being-classified-as-spam"&gt;https://serverfault.com/questions/48428/how-to-send-emails-and-avoid-them-being-classified-as-spam&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Plus other things that you need to worry about that I probably failed to mention here. These are all good if you love to DIY but if you want a more convenient way to monitor cron jobs, an alternative and better way is to use a cron job monitoring tool like CronMonit.&lt;/p&gt;

&lt;p&gt;Setting up a cron job to be monitored via CronMonit only takes less than 5 minutes. You just have to create a check using CronMonit’s dashboard and configure your cron job to ping the check once it is done running by sending an HTTP request to the given ping URL.&lt;/p&gt;

&lt;p&gt;E.g,&lt;/p&gt;

&lt;p&gt;If your cron job is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;* * * * * script.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;..it will become:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;* * * * * script.sh &amp;amp;&amp;amp; curl -fsS --retry 3 https://cronmonit.app/ping-check/91b5a171-6721-4657-b05e-35f5dde5dc0f &amp;gt; /dev/null&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once your cron job pings the check for the first time, CronMonit will start monitoring your cron job. If ever your cron job fails (e.g, an error happens or the cron job doesn’t run at all), you’ll get notified via email.&lt;/p&gt;

&lt;p&gt;And by using CronMonit, if cron is not running at all or if the server is down, you’ll still get notified that there’s a problem with your cron job!&lt;/p&gt;

&lt;p&gt;You’ll also get a simple dashboard for viewing monitored cron jobs where you can easily see which jobs are up or down:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DTL8-ut7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/cv6csg1avu45ti4jtw3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DTL8-ut7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/cv6csg1avu45ti4jtw3g.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is really useful especially if you have a lot of cron jobs. You’ll also be able to view logs of pings and status changes which provides some useful insights about your cron jobs:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--77ljXlhQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/c1nn603mkwq3gbpuny2b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--77ljXlhQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/c1nn603mkwq3gbpuny2b.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--77SKCRN5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/51gy6gvjcc1a4pmmg0zg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--77SKCRN5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/51gy6gvjcc1a4pmmg0zg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checks can be organized by projects too:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ReO9_L6F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/v44wddxit6gswaydx4qz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ReO9_L6F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/v44wddxit6gswaydx4qz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We're currently using it on a project that uses lots of cron jobs.&lt;/p&gt;

&lt;p&gt;Signup and start monitoring your cron jobs for free: &lt;a href="https://cronmonit.app"&gt;https://cronmonit.app&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>monitoring</category>
      <category>cronjobs</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Deploying a Rails App With No Downtime and No Hanging Requests</title>
      <dc:creator>John</dc:creator>
      <pubDate>Sat, 30 Nov 2019 14:58:46 +0000</pubDate>
      <link>https://dev.to/john200ok/deploying-a-rails-app-with-no-downtime-and-no-hanging-requests-nfc</link>
      <guid>https://dev.to/john200ok/deploying-a-rails-app-with-no-downtime-and-no-hanging-requests-nfc</guid>
      <description>&lt;p&gt;While working on CronMonit, I needed a way to be able to do deployments with zero-downtime and zero hanging requests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cronmonit.app/"&gt;CronMonit&lt;/a&gt; is a cron monitoring tool and it is able to monitor cron jobs by receiving pings (HTTP requests). A service like this can't have many downtimes or hanging requests because even just missing a few pings will cause issues for its users. Like a "cron job is down" email notification being sent even if the cron job is not really down. And because I do deployments frequently, having a way to do deployments with zero downtime and zero hanging requests is crucial.&lt;/p&gt;

&lt;p&gt;This is the current tech stack of CronMonit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rails 6&lt;/li&gt;
&lt;li&gt;Puma&lt;/li&gt;
&lt;li&gt;Nginx&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of them are running on a single $5 DigitalOcean droplet (Ubuntu 18.04 LTS).&lt;/p&gt;

&lt;p&gt;Luckily, it is very easy to a deployment with no downtime and no hanging requests on a rails app using puma web server. Puma has a feature called "phased restart" which kills puma workers one-by-one.&lt;/p&gt;

&lt;p&gt;To use it, just spawn up at least 2 puma workers.&lt;/p&gt;

&lt;p&gt;E.g,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RAILS_ENV=production bundle exec puma -w 2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then when you need to restart puma, use the phased restart feature:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bundle exec pumactl phased-restart&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here's an example scenario that explains the process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do code changes on your local development environment&lt;/li&gt;
&lt;li&gt;Commit or merge the changes to master branch&lt;/li&gt;
&lt;li&gt;Push the changes on master branch to your central git repository (e.g, Github)&lt;/li&gt;
&lt;li&gt;SSH into your server&lt;/li&gt;
&lt;li&gt;cd into the directory of the git repository on your server&lt;/li&gt;
&lt;li&gt;Pull updates from master branch (e.g, git pull origin master)&lt;/li&gt;
&lt;li&gt;Then restart puma using phased restart&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it!&lt;/p&gt;




&lt;p&gt;If you're using cron jobs or scheduled tasks, you can monitor them using CronMonit for free: &lt;a href="https://cronmonit.app/"&gt;https://cronmonit.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's a blog post on how it works:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/john200ok/free-and-painless-cron-job-monitoring-via-cronmonit-8n9"&gt;https://dev.to/john200ok/free-and-painless-cron-job-monitoring-via-cronmonit-8n9&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>devops</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
