December, 2018
4
While ending this year, we release all developments that occurred during the last months, which are now ready to go in production. We’ve got a lot of new features to improve your experience with your alwaysdata’s account.
Some Web apps or services sometimes require you to run tasks periodically. From a WordPress blog where you want to rely on an OS scheduled tasks, to a broker that you need to purge from its messages queue periodically, or an RSS feed reader that you want it to retrieve its new articles at a given time, there’s plenty of use-cases.
The main point is: services may need to run commands, or get URLs, without any user interactions. Every time you face this case, you need to register a scheduled task.
Our platform use Debian as its base and you’ve got full access to your Unix account on the servers. It means you can register your tasks by editing your user’s crontab with crontab -e
.
For us, it wasn’t enough. For two reasons. The first one is that it splits the administration logic between our admin panel and the Unix system. The second one is the crontab syntax so dull.
The bonus1) point is also that a task scheduled using crontab means its declaration stays on a server, which is not the server that runs your services2). When we move your account to another server3) we had to take care of potential cron tables, which breaks the unity and simplicity of our platform.
So, we added a Scheduled tasks support directly in your interface!
If you need to register a new task for any of your services, go to this new section in the administration panel and add a new task.
You have to fill in the form with few pieces of information:
- The command(s) you want to run, or the URLs you want to GET: if you need to ping one or more URLs to trigger distant services, just fill them in; otherwise, declare the command line to execute.
- The periodicity you want the task to repeat. You can specify a given time or a time interval. If this field isn’t powerful enough for your need, feel free to come back to the crontab syntax to precisely run your task.
That’s all. Your task is now registered, and the platform takes care to run it.
About the WordPress example aforementionned, you can register a task like php $HOME/wordpress/htdocs/wp cron event run --due-now
that you can run every 10 minutes4).
All timer features are also available through the API, to allow you to easily register programmatically any scheduled task you need.
We do not rely on existing cron tools for those tasks, but instead use our own implementation: aljob. This for two reasons:
- Scheduled tasks aren’t executed right at the given time, but in a minute range. It means that a task scheduled at 00:00 will run at some point between 00:00:00 and 00:00:59. When you’ve got hundreds of tasks scheduled at midnight5), it prevents an overload of the servers.
- If you often run a long task (e.g. every 10 minutes), our daemon automatically detect that the previous task didn’t exited, and skip the new one, automatically preventing the overload and race conditions in your long loop execution.
Want funny stuff? You can run tasks even without any service installed in your account. Here’s a custom command I run every day:
1 2 | curl -L "https://duckduckgo.com/news.js?l=fr-fr&o=json&q=google&vqd=3-64264753228138754347320549738585677647-267411849122617233633307047978420270659" | jq '.results | to_entries | .[].value | "\(.title) [\(.url)] (\(.relative_time))"' | mail -s "Daily news about Google" m4dz@alwaysdata.com |
It pings the DuckDuckGo news API and queries it about contents related to Google6), then filter the returned JSON to extract the news’ title, URL, and date. It finally compiles and sends it to my mail, so I’ve got my daily digest about Google related stuff in my mailbox.
Scheduled tasks panel is now available in your administration panel. We will remove the crontab support for shared hosting soon. If you rely on crontab for your tasks, they’ll be reported automatically to scheduled tasks. VPS and Dedicated hosting will have both scheduled tasks and native crontab available and can use whatever solution their prefer.
If you spot any improvement to this feature, feel free to report it. We’re also curious about what use you can have of the scheduled tasks, use comments to surprise us!
Other features are on their way to production. Stay tuned and keep an eye to our Twitter #advent thread as more news are coming.
Notes
↑1 | and technical |
---|---|
↑2 | our SSH servers and HTTP servers aren’t the same ones |
↑3 | which occur transparently every day and then |
↑4 | do not forget to disable the WordPress fake embedded cron by adding define('DISABLE_WP_CRON', true); in your wp-config.php file |
↑5 | like on our Shared hosting plans |
↑6 | yeah, I like to troll them all |
no comments