Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc: document crontab trigger #59

Merged
merged 10 commits into from
Dec 3, 2024
117 changes: 114 additions & 3 deletions content/docs/custom-commands/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Example:
These triggers will run the command at a regular interval of time -- for instance, every 2 hours -- in the selected
channel.

When using an interval trigger, the custom command does not receive any user or member context. Thus, `{{ .User.ID }}`
When using a time-based trigger, the custom command does not receive any user or member context. Thus, `{{ .User.ID }}`
and similar templates will result in no value and member-dependent functions such as `addRoleID` will fail.

![Overview of interval configuration options.](interval_trigger_options.png?width=60vw)
Expand All @@ -215,17 +215,24 @@ and similar templates will result in no value and member-dependent functions suc

Interval (**1**) sets how often the command will run in **hours** or **minutes**.

{{< callout context="caution" title="Warning: Interval duration limits" icon="outline/info-circle" >}}

The minimum interval is 5 minutes, and the max is 1 month. Up to 5 interval triggers may have an interval of 10 minutes
or shorter.

{{< /callout >}}

Channel (**2**) specifies a channel to run the command in. The response, if any, will be sent to this channel.

You must specify a channel to run time-based commands in even if the command doesn't output a message.

Excluding hours and/or weekdays (**3**) prevents the command from triggering during those hours or weekdays. **This uses
UTC time**, not your local timezone.

When editing an interval command, a **Run Now** button appears at the bottom of the page. It executes the command as
long as the command is not disabled and a channel is selected. Running an interval command using this button reschedules
all subsequent runs based off the current time.

You must specify a channel to run interval commands in even if the command doesn't output a message.

##### Component

[In-depth Interactions Guide](/docs/reference/custom-interactions)
Expand All @@ -242,6 +249,110 @@ The modal trigger is used to trigger custom commands via submitting a modal.

The trigger is matched using [RegEx](/docs/reference/regex).

##### Crontab

This trigger will run the command periodically using [Cron Syntax](https://en.wikipedia.org/wiki/Cron) to schedule runs.
In contrast to interval triggers, which run a command with a fixed delay but unknown time, cron triggers can be made to
execute periodically at fixed times, dates, and/or intervals. For instance, you could schedule execution for 23:45 every
Saturday.

When using a time-based trigger, the custom command does not receive any user or member context. Thus, `{{ .User.ID }}`
and similar templates will result in no value and member-dependent functions such as `addRoleID` will fail.

![Overview of crontab configuration options.](crontab_trigger_options.png?width=60vw)

<center>

**1** Cron Expression **2** Channel **3** Excluding hours/weekdays

</center>

Cron Expression (**1**) defines the expression used to schedule the cron job. It uses the standard expression format
(see below). It does not support predefined schedules such as `@hourly`. The cron scheduler uses UTC always.

A cron expression represents a set of times, using 5 space-separated fields.

Field name | Mandatory? | Allowed values | Allowed special characters
---------- | ---------- | -------------- | --------------------------
Minutes | Yes | 0-59 | * / , -
Hours | Yes | 0-23 | * / , -
Day of month | Yes | 1-31 | * / , - ?
Month | Yes | 1-12 or JAN-DEC | * / , -
Day of week | Yes | 0-6 or SUN-SAT | * / , - ?

jo3-l marked this conversation as resolved.
Show resolved Hide resolved
To read more about the supported format of cron expressions, visit [Robfig's Cron package documentation - Expression
Format](https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format).

{{< callout context="tip" title="Tip: Debugging Cron Expressions" icon="outline/rocket" >}}

To help build and debug cron expressions, we reccomend using [Cronitor's Crontab Guru](https://crontab.guru/) or a
similar site. Note that predefined schedules such as `@hourly`, and the use of `7` in the DOW field may parse correctly
l-zeuch marked this conversation as resolved.
Show resolved Hide resolved
on Corntab Guru, but are not supported with YAGPDB.

{{< /callout >}}

**Special Characters**

- Asterisk ( * )

The asterisk indicates that the cron expression will match for all values of the field; e.g., using an asterisk in the
5th field (month) would indicate every month.

- Slash ( / )

Slashes are used to describe increments of ranges. For example 3-59/15 in the 1st field (minutes) would indicate the 3rd
minute of the hour and every 15 minutes thereafter. The form "*\/..." is equivalent to the form "first-last/...", that
is, an increment over the largest possible range of the field. The form "N/..." is accepted as meaning "N-MAX/...", that
is, starting at N, use the increment until the end of that specific range. It does not wrap around.

- Comma ( , )

Commas are used to separate items of a list. For example, using "MON,WED,FRI" in the 5th field (day of week) would mean
Mondays, Wednesdays and Fridays.

- Hyphen ( - )

Hyphens are used to define ranges. For example, 9-17 would indicate every hour between 9am and 5pm inclusive.

- Question mark ( ? )

Question mark may be used instead of '*' for leaving either day-of-month or day-of-week blank.

Quick Examples:

```txt
45 23 * * 6
Run once a week, on Saturday at 23:45.

0 * * * *
Run once an hour, beginning of hour.

0 0 * * *
Run once a day, midnight.

0 0 * * 0
Run once a week, midnight between Sat/Sun.

0 0 1 * *
Run once a month, midnight, first of month.

0 0 1 1 *
Run once a year, midnight, Jan. 1st.
```

{{< callout context="caution" title="Warning: Cron interval limits" icon="outline/info-circle" >}}

Your cron expression must schedule jobs with greater than a 10 minute interval between executions.

{{< /callout >}}

Channel (**2**) specifies a channel to run the command in. The response, if any, will be sent to this channel.

Excluding hours and/or weekdays (**3**) prevents the command from triggering during those hours or weekdays. **This uses
UTC time**, not your local timezone.

You must specify a channel to run time-based commands in even if the command doesn't output a message.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to the rest of the image caption at the start of this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure I understand what you’re asking for.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SoggySaussages I cannot see any change addressing this comment--did you perhaps forget to push your changes or publish your response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, maybe you can’t see my response. I replied to this saying “I’m not sure I understand what you’re asking for,” which still stands.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have this section (after the callout and until the next heading) moved further up, before the table explaining how a cron expression is structured.

As it stands, we have a screenshot of the page, with its appropriate caption, then go to great lengths of explaining a single marked thing in that screenshot (the cron expression labelled 1), then have more references to the image. This makes this section awkward to read--a reader would have to scroll back up for the visual reference the image is supposed to provide.

Though these additional fields are quickly explained, I'd rather have them at the top with the description of the cron expression, and only after the image is fully describe we explain how to construct a cron expression. That way, we have the image closer to the text that is describing it, eliminating or reducing the need to scroll back up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's done.


#### Case Sensitivity

Any commands which allow you to specify trigger text (command, regex, exact match, and so on) have a **Case
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.