Skip to content

Commit 8bc661d

Browse files
iamdarkledavwheat
andauthored
Add Flarum scheduler guide to docs (#459)
* Add Flarum scheduler guide to docs * Apply suggestions from code review Co-authored-by: David Wheatley <david@davwheat.dev> --------- Co-authored-by: David Wheatley <david@davwheat.dev>
1 parent a30977e commit 8bc661d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

docs/scheduler.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Scheduler
2+
3+
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](https://en.wikipedia.org/wiki/Cron) on cron.
4+
5+
## Why should I care?
6+
7+
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!
8+
9+
## What extensions currently use the scheduler?
10+
11+
Some of the most popular examples are the following:
12+
13+
- [FoF Best Answer](https://github.com/FriendsOfFlarum/best-answer)
14+
- [FoF Drafts](https://github.com/FriendsOfFlarum/drafts)
15+
- [FoF Sitemap](https://github.com/FriendsOfFlarum/sitemap)
16+
- [FoF Open Collective](https://github.com/FriendsOfFlarum/open-collective)
17+
- [FoF Github Sponsors](https://github.com/FriendsOfFlarum/github-sponsors)
18+
19+
## Ok, let's get this setup!
20+
21+
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:
22+
23+
```
24+
sudo apt-get update
25+
sudo apt-get install cron
26+
```
27+
28+
In case you are using a RHEL based Linux distribution (CentOS, AlmaLinux, Rocky Linux...), install cron like this:
29+
30+
```
31+
sudo dnf update
32+
sudo dnf install crontabs
33+
```
34+
35+
Once you have cron installed, let's create the one and only entry you need for Flarum:
36+
37+
```
38+
crontab -e
39+
```
40+
41+
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.
42+
43+
```
44+
* * * * * cd /path-to-your-project && php flarum schedule:run >> /dev/null 2>&1
45+
```
46+
47+
`* * * * *` tells cron to run your command every minute.
48+
49+
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](https://crontab.guru) to easily get the desired string.
50+
51+
`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.
52+
53+
Lastly `>> /dev/null 2>&1` suppresses any output from the command.
54+
55+
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.

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = {
4848
'languages',
4949
'themes',
5050
'mail',
51+
'scheduler',
5152
'console'
5253
]
5354
},

0 commit comments

Comments
 (0)