DEV Community

okayshankha
okayshankha

Posted on • Originally published at devconcludes.com on

You need a better solution for Cron Jobs

Image description

If you are coming from a technical background, the chances are, you have already used it or at least have heard of Cron Jobs. Even if you don’t have a technical background, no worries, I got you covered. I will be explaining the Cron Job concept briefly to you.

In this article, we are going to discuss the traditional approach for Cron Jobs and what are the flaws of using it. So, without any further do, let’s get a brief understanding of what exactly Cron Job is.

What is Cron Job?

A cron job is a program or script that runs automatically at certain times. The name comes from the Unix operating system, where it was originally developed. In Linux systems, cron jobs run every minute, hour, day, week, month, quarter, year, etc.

When you schedule something to happen at a specific time, you want it to happen exactly then. That’s why you need a cron job. If you’re looking for ways to automate processes, you can create a cron job to execute a task. For example, you can schedule a backup to occur daily.

I’m sorry if that was, a little overwhelming, but hopefully got the idea. Let’s have a quick overview first what is the traditional way to do it.

The traditional setup for Cron Jobs in Linux systems

Well, the concept of Cron Jobs came from the Linux systems. They had this implementation to run a command at a specified time.

We could access Cron Jobs via a Linux command called “crontab “. There are some basic syntaxes to get started.

Cron job syntaxes in Linux Systems

Here I’m sharing some of the crontab commands to do things.

  • crontab -e: edits crontab entries to add, delete, or edit cron jobs.
  • crontab -l: list all the cron jobs for the current user.
  • crontab -u username -l: ** ** list another user’s cron jobs.
  • crontab -u username -e: ** ** edit another user’s cron jobs.

If you want to learn more about crontabs, check out this awesome article I found.

Cron Jobs commands may vary from OS to OS. It means Linux-based systems have crontab but, what about Windows Systems? As a developer, you might not know where your application is going to be deployed! And depending on the OS you need to set up cron jobs every time. I think this is hard.

Let’s assume, you are working on some project, say a NodeJS project, and you need to set up Cron Jobs for your application. What if, instead of you setting it up at the OS level, you could do the same in your NodeJS program itself?

So, for that, if you do a quick Google search, it will come up with an NPM package called “ node-cron “. Other programming languages have packages as well to implement in-code corn job setups.

Continue reading the original post You need a better solution for Cron Jobs

Top comments (0)