In simple terms, a Cron is a time-based job scheduler. It is used to do the schedule jobs like commands or shell scripts at the time defined to do that.
Let's say you want to clear the cache of your website, download the emails, or just publish a scheduled content every 20 minutes. You can't do it every time. 24*7. This is where Cron comes in to help to perform the actions without the manual assistance.
It will automate the system maintenance or the administrator role using its general purpose nature. Which means if once you define the time interval for a process, it will run automatically.
The cron will execute the commands at the date and time specified to it. Your scheduled activities or commands may be either - action or time-based. Basically any recurring task.
In Drupal, we use the Ultimate Cron module to allocate the different time period to every cron job.
How to allocate different time period to every cron job?
Ultimate Cron module runs the jobs individually, in parallel using the configurable rules, load balancing, and pool management.
During the installation and the maintenance of your website, it is important to set up the cron to update the Drupal core, module and removing the temporary files.
Setting up the module is important to regularly check the updates. Means when you will schedule the job for your website then at the defined rule the automated job will perform the action.
Installing the Cron Module
You can easily download and enable the module using the Drush command.
$ Drush dl ultimate_cron
$ Drush en ultimate_cron
Or simply you can download the module from Drupal.org.
Install and enable it
- This will be easier for you if you will let the Drupal do it for you. Means in Drupal, it schedules the cron jobs by default. If you want to manage this automate cron, and then you can do it simply via administrative UI.
- Go to >> Configuration >> System >> Cron “/Drupal/admin/config/system/cron”.
- The default frequency is set to 3 hours. If you do not want to let the cron run automatically then you may disable it. Change the 'Run cron every' drop down to 'never'.
- To allocate the different period to every cron job Go to Admin > Config system > Cron jobs. Here you may come across the following page:
- Choose a title/job to allocate the time. Here I am going to schedule the time to clean up the cache. Click on Crontab.
- Set the rule to allocate the time. To fill the rule for the setting of the time allocation you will find the rule on the same page.
Advantages of Cron Job
- By using the module, parallel execution of cron jobs is possible.
- You can enable or disable the cron job as per your requirement. You can also set the rules for the cron job (like the time interval).
- You will be able to allow the multiple rules for a cron job like you can allocate the different time period to every job.
- It supports Drush. Using the Drush command on your command line you can enable or disable, start and list the cron jobs.
- You can also see the overview and the long history of the Cron job.
- When an error will occur then it will send you the status or the error message which is easy to understand and debug the troublesome jobs.
- In the Drupal, it automatically updates the index of site content used by the search module.
- Performs routine maintenance tasks, such as removing older rows from logs, for the system module.
The cron job is a time-triggered action. And it is performed by the hosting server of your website. Or your site may also be on the localhost. You can check the status report of your cron at admin/reports/status.
Let us know in the comments below how you use or have used the Cron module.
Subscribe
Related Blogs
In conversation with Danish Usmani, CEO, OpenSense Labs
In a year-end interview, CEO Danish Usmani showcases OpenSense Labs' achievements, emphasising new client partnerships and…
Why should you prioritize lean digital in your company?
We are living in an era where the change and innovation rate is just so high. If you want your organization to reach new…
How to measure your open source program’s success?
Along with active participation, it is very important to look after the ROI of open-source projects, programs, and…