返回介绍

Scheduler

发布于 2024-06-22 20:04:58 字数 4104 浏览 0 评论 0 收藏 0

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文