Get to know the new Joomla! Task Scheduler
Joomla’s Task Scheduler is a new addition to the core operating system of Joomla! 4.1. The Joomla development team added it to the core to help automate repetitive tasks that maybe you’d rather not do. You can use the Task Scheduler for a wide variety of maintenance and reporting tasks, and it runs on a Plugin system that can be added to and customised.
The task scheduler runs the task detailed in a Plugin via a cron job from within Joomla’s admin.
What’s a cron job? You ask. Let's dig into that now.
What’s a Cron Job?
Have you ever installed a Joomla Component only to find out you then need to set up a cron job for it to work completely on your hosting control panel? So have we.
A cron job is used to automate some part of the Components operation. This is usually a repetitive task that you’d prefer not to have to do! Because of this, many website owners forget to carry out these tasks. As a result, their website may not be as good as it could be.
Cron jobs are generally used to process email queues in newsletter systems, or to synchronise e-commerce orders with a delivery platform or to clean up cache and so on.
One problem of setting up a cron job to run on your server is knowing how to format the command line in the control panel for the cron job, so it triggers and runs as it should.
Do you know where your PHP folder is? What about the full URL to the cron file?
These are things the Component author can’t help you with and are invariably different between hosting companies.
A typical cron command line has three parts and may look something like this:
The first part is the route to your PHP folder, then there's an extra space, and finally the URL to the script that the cron will execute.
Then you need to decipher the timings that trigger the cron job. You need to decide how frequently it should run, and will your hosting provider even allow it to run that frequently, or at all? Some hosting companies put restrictions on their cron job schedules to help maintain resources across the server. This is almost always true if you host your website on a shared server.
Usually a VPS server or dedicated server won’t have these restrictions, as all the resources of the server are yours. But, these servers will cost you more to run than shared hosting, which is where many small business and personal websites live.
An experienced web developer understands this, but many people who want to run their own website often struggle with these settings. They then end up reaching out for support to help them get the Component working properly.
Joomla’s new task scheduler takes away some of this pain and aims to keep you on your website, in familiar surroundings. Rather than being up to your elbows in the nuts and bolts of your web server’s control panel.
Task Scheduler Overview
Now we know what a cron job is, let’s now take a look at some of Joomla’s Task Scheduler’s features, and some of the things that make this a great new addition to Joomla!’s core functions.
Task Scheduler allows you, the website owner, to create web-based cron jobs from an environment that you’re already familiar with, and comfortable working within.
Find the Task Scheduler
You can find the Task Scheduler in the System Dashboard, which is accessed from the main menu in the ‘Manage’ section.
Select A Task To Run
If you open the task Scheduler and select ‘New’, the currently installed task Plugins will be displayed. You can then select the task you’d like to schedule. By default Joomla 4.1 ships with 9 pre-installed task Plugins, some useful. Others are demo ideas.
If you have some extensions installed, for example Akeeba Backup, then their Task Schedule plugins will also be available to use.
Select Your Task Options
The options available from the Plugin’s new task menu simplify the cron job setup and allow you to select how you’d like the cron job to run. You set the frequency for the cron job to run in the Basic Fields, and if the cron job requires any extra settings, or options to run, you can set them in the Task Parameters section. The Advanced tab is where you can choose the priority for the cron job, over other tasks you may want to run. It’s also the place to tell the Plugin how you want to be notified that the cron job ran and was successful, or not.
Once you’ve set up the task, you can always go back and from the same settings sections, change how you want the task to run in the future.
It’s good practice to schedule tasks sensibly, especially on a shared server. Do you really need to set a task to resize a photo every minute when you only have one new article added weekly? If you have multiple tasks running, stagger the start times for the cron.
- Task 1 runs every Monday at 11:30
- Task 2 runs every hour, on the hour.
- Task 3 runs every 4 hours and 18 minutes
Staggering the times you run the tasks also puts less demand on your server, which in turn keeps those server resources for your website, thus keeping your visitors happy using a fast website. Instead of one bogged down with unnecessary tasks running in the background.
You could also trigger the tasks to run when your website is less likely to receive many visitors. Running tasks during the evening, when most people are at home surfing the net, is probably unwise! Or, you can trigger the task to run manually any time you chose.
In the Task Scheduler’s options, you can choose how the tasks get triggered. Do you want them to run as specified in the tasks settings? Or, maybe it’s a task that needs to be run when someone visits a specific webpage. You can even set up a Web Cron URL with the Task ID that you want to run set as a query string (&ID=1). This means that you can run the task in question via an external trigger from a different website or app.
Many Joomla extension developers will include task plugins with their extensions to give you the option to automate certain tasks. For example, the popular Joomla backup extension Akeeba, already includes task Plugins in their Pro versions to set crons to run their backup processes.
Design Your Own Task Plugin
But, you’re not limited to what established extension developers give you. You can develop your own Plugins to trigger events you’d like to happen. The task schedule Plugins follow a simple Plugin syntax that allows the task scheduler to connect to them, and fire the Plugin’s commands on cue. Although you’ll have to have a solid understanding of PHP to write the necessary functions needed to action your task. Task Scheduler Plugins also give you the functionality to include Joomla’s new API functions, which open up a massive new level of functionality to your website.
Below is an example of Joomla's new Task Scheduler to base your next plugin on:
Task Scheduler Plugin Ideas
Apart from task plugins developed by Joomla component authors there are hundreds of other potential uses for Joomla’s new task scheduler. Limited only by your own imagination and need.
Here’s a list of 20 ideas to get you started.
- Resizing images uploaded by your authors so your website design remains consistent.
- Automatically regenerate your sitemap to reflect new articles.
- To ping Google to tell it you’ve published new content.
- To send you daily reports of website activity.
- To automate Component updates.
- To automate partial or full backups.
- To send out emails to your users/groups with data, you upload to your Google drive.
- To send you a new user report.
- To send you a list of new articles/posts/comments submitted.
- To send you daily logs from the website.
- Then to purge and delete those logs.
- To upload articles as social media posts to your social media channels.
- Change site or admin colour schemes light/dark mode automatically.
- Change website templates based on seasonal celebrations (Christmas, Easter, New Year, etc.)
- Send backup archives to cloud storage.
- Restart Node.js If you have an app that uses node.js on your server.
- Gather system health information and send via email.
- Send visitor data to superuser.
- Monitor and report hosting uptime/ downtime.
- Send pertinent new articles to various user groups.
What will you use Joomla!’s new Task Scheduler for?
Read this article in German: Geplante Aufgaben in Joomla 4.1 - eine neue Funktion
This is powerful, can wait playing with that. I want to tanks the Joomla Team for the great new features of Joomla.
Nice article, Joomla has always need this feature.
The simple code put above is really handy and appreciated.
Hi, Thank you for your interesting article. But I have one question. I have done a fast test and it seems that my task only runs if someone visits the site. How do I configure the task to run without visits (e.g nighttime). Its it the cron syntax or something else?. Does this require a late PHP version to work (i.e to run without visits)
Hi, is it that my Scheduled Tasks only run when I am logged in to the backend ? Or have I set up something wrong?
in the meantime I have done some tests. It seems that the Scheduled Tasks are only executed if there are activities in the backend or frontend. Not the pure call of the website, but e.g. the call of the login mask. This is perfect for my current requirements! Ingenious!