feat: allow cron-entries to set a per-entry MAILTO
The `cron-entries` trigger is now passed `json` as a second argument, and plugins may print each task as a json object on its own line. A task that sets a `mailto` is written to the crontab under a `MAILTO` of its own, and its output is mailed to that address as well as appended to its log file, so plugins such as the datastore plugins can have the output of a specific scheduled task mailed to a specific person.
This commit is contained in:
8 files changed
+474
-62
No files matched your search
@@ -101,6 +101,38 @@ func TestDokkuRunCommandAltCommandWithLogFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestDokkuRunCommandAltCommandWithMailto pins that an injected task with its
|
||||
// own MAILTO keeps its output on stdout, where cron mails it from, while still
|
||||
// appending it to the log file.
|
||||
func TestDokkuRunCommandAltCommandWithMailto(t *testing.T) {
|
||||
task := CronTask{
|
||||
ID: "abc123",
|
||||
AltCommand: "/usr/bin/some-internal-task",
|
||||
LogFile: "/var/log/dokku/internal-task.log",
|
||||
Mailto: "ops@example.com",
|
||||
}
|
||||
|
||||
got := task.DokkuRunCommand()
|
||||
want := "/usr/bin/some-internal-task 2>&1 | tee -a /var/log/dokku/internal-task.log"
|
||||
if got != want {
|
||||
t.Errorf("DokkuRunCommand() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDokkuRunCommandAltCommandWithMailtoAndNoLogFile(t *testing.T) {
|
||||
task := CronTask{
|
||||
ID: "abc123",
|
||||
AltCommand: "/usr/bin/some-internal-task",
|
||||
Mailto: "ops@example.com",
|
||||
}
|
||||
|
||||
got := task.DokkuRunCommand()
|
||||
want := "/usr/bin/some-internal-task"
|
||||
if got != want {
|
||||
t.Errorf("DokkuRunCommand() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDokkuRunCommandAppTaskIgnoresLogFile pins that LogFile is honored only
|
||||
// for internally injected tasks from the cron-entries trigger. App tasks never
|
||||
// interpolate a path into the crontab line - their output is shipped by the
|
||||
|
||||
Reference in new issue
Block a user