这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/processes/scheduled-cron-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,30 @@ When running scheduled cron tasks, there are a few items to be aware of:
- Schedules are performed on the hosting server's timezone, which is typically UTC.
- At this time, only the `PATH` and `SHELL` environment variables are specified in the cron template.
- A `MAILTO` value can be set via the `cron:set` command.
- A `MAILFROM` value can be set via the `cron:set` command.
- Each scheduled task is executed within a one-off `run` container, and thus inherit any docker-options specified for `run` containers. Resources are never shared between scheduled tasks.
- Scheduled cron tasks are supported on a per-scheduler basis, and are currently only implemented by the `docker-local` scheduler.
- Tasks for _all_ apps managed by the `docker-local` scheduler are written to a single crontab file owned by the `dokku` user. The `dokku` user's crontab should be considered reserved for this purpose.

#### Specifying a MAILFROM value

> [!IMPORTANT]
> New as of 0.35.14

Users can specify a value for `MAILFROM` via the global `mailfrom` cron property by using the `cron:set` command.

```shell
dokku cron:set --global mailfrom example@example.com
```

All output for individual cron runs will be sent from the specified email.

Cron emails can be reset to use the system email by running the `cron:set` command for the global `mailfrom` property with no value.

```shell
dokku cron:set --global mailfrom
```

#### Specifying a MAILTO value

By default, cron tasks complete and do not perform any reporting. Users can specify a value for `MAILTO` via the global `mailto` cron property by using the `cron:set` command.
Expand Down
6 changes: 4 additions & 2 deletions plugins/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
var (
// DefaultProperties is a map of all valid cron properties with corresponding default property values
DefaultProperties = map[string]string{
"mailto": "",
"mailfrom": "",
"mailto": "",
}

// GlobalProperties is a map of all valid global cron properties
GlobalProperties = map[string]bool{
"mailto": true,
"mailfrom": true,
"mailto": true,
}
)

Expand Down
5 changes: 5 additions & 0 deletions plugins/cron/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
}

flags := map[string]common.ReportFunc{
"--cron-mailfrom": reportMailfrom,
"--cron-mailto": reportMailto,
"--cron-task-count": reportTasks,
}
Expand All @@ -28,6 +29,10 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
return common.ReportSingleApp("cron", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
}

func reportMailfrom(_ string) string {
return common.PropertyGet("cron", "--global", "mailfrom")
}

func reportMailto(_ string) string {
return common.PropertyGet("cron", "--global", "mailto")
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/cron/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package cron
import "errors"

func validateSetValue(appName string, key string, value string) error {
if key == "mailfrom" && appName != "--global" {
return errors.New("Property cannot be specified on a per-app basis")
}

if key == "mailto" && appName != "--global" {
return errors.New("Property cannot be specified on a per-app basis")
}
Expand Down
3 changes: 3 additions & 0 deletions plugins/cron/templates/cron.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{ if .Mailfrom -}}
MAILFROM={{ .Mailfrom }}
{{ end -}}
{{ if .Mailto -}}
MAILTO={{ .Mailto }}
{{ end -}}
Expand Down
6 changes: 5 additions & 1 deletion plugins/cron/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import (

// TriggerCronGetProperty writes the cron key to stdout for a given app container
func TriggerCronGetProperty(appName string, key string) error {
if key != "mailto" {
validProperties := map[string]bool{
"mailfrom": true,
"mailto": true,
}
if !validProperties[key] {
return errors.New("Invalid cron property specified")
}

Expand Down
11 changes: 9 additions & 2 deletions plugins/scheduler-docker-local/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,21 @@ func writeCronEntries() error {
return deleteCrontab()
}

results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
resultfromResults, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "cron-get-property",
Args: []string{"--global", "mailfrom"},
})
mailfrom := resultfromResults.StdoutContents()

mailtoResults, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "cron-get-property",
Args: []string{"--global", "mailto"},
})
mailto := results.StdoutContents()
mailto := mailtoResults.StdoutContents()

data := map[string]interface{}{
"Commands": commands,
"Mailfrom": mailfrom,
"Mailto": mailto,
}

Expand Down
Loading