指南
- 介绍
- Contribute
- 部署
- 管理
- 高级
内部文档
扩展
- Main 核心概念
- 参考指南
- 进阶指南
- 更新指南
Scheduler
The Flarum scheduler allows extensions to automate certain tasks effortlessly. In this guide we will see how to set it up. We won't go into the details of cron itself, but if you want to read more about it, I suggest you take a look at this Wikipedia article on cron.
Why should I care?
Quite simply, a growing list of extensions now support handling certain functions automatically for you, completely behind the scenes. Wondering why fof/drafts
'scheduled drafts' are not posting, or fof/best-answer
'remind users to set a best answer after X days' does not fire? That'll be because they will setup themselves with the scheduler service, but without a one-liner cron job, nothing will happen!
What extensions currently use the scheduler?
Some of the most popular examples are the following:
Ok, let's get this setup!
Most (if not all) Linux distros either come with, or can have, cron installed. For example, on Debian and Ubuntu based systems, you can install cron
like this:
sudo apt-get update
sudo apt-get install cron
In case you are using a RHEL based Linux distribution (CentOS, AlmaLinux, Rocky Linux...), install cron like this:
sudo dnf update
sudo dnf install crontabs
Once you have cron installed, let's create the one and only entry you need for Flarum:
crontab -e
This will open the cron editor. You may or may not have other entries there. Add this line, and remember to leave an empty line at the bottom.
* * * * * cd /path-to-your-project && php flarum schedule:run >> /dev/null 2>&1
* * * * *
tells cron to run your command every minute.
In case you want to use a different value and don't know exactly how cron expressions work, you can use a cron expression generator to easily get the desired string.
cd /path-to-your-project && php flarum schedule:run
executes Flarum's scheduler to trigger any tasks currently waiting to be run. If PHP isn't in your system's path, you may need to experiment with setting the full path to PHP.
Lastly >> /dev/null 2>&1
suppresses any output from the command.
Voila! Now any extension that registers a task to run, anything from every minute to daily, monthly, yearly - whatever - will now run on your server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论