feat(11-02): add schedule:run as a scheduler process and a cron --once mode

- schedule:run runs a worker on the scheduled queue with every plugin's periodic jobs
- schedule:run --once runs entries due in the current app.timezone minute without River,
  warns and skips unregistered commands, and returns the first command error
- summer schedule:run delegate forwards --once
- tests for --once minute matching, forged-entry skipping (T-11-09) and ByPeriod dedupe
This commit is contained in:
Jakub Zych
2026-09-29 22:34:21 +02:00
parent d9f939a1ea
commit 2237a640d2
7 changed files with 521 additions and 18 deletions

View File

@@ -6,9 +6,9 @@ import (
"os"
"strings"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/internal/build"
"git.golem15.com/golem15/summercms/internal/dev"
"git.golem15.com/golem15/summercms/modules/bonfire"
)
func main() {
@@ -43,6 +43,7 @@ func toolCommands() []bonfire.Command {
delegateCommand("migrate:status", "Show per-plugin migration history in the app binary"),
delegateCommand("serve", "Run the app HTTP server"),
delegateQueueWorkCommand(),
delegateScheduleRunCommand(),
delegateCommand("queue:clear", "Clear pending queued jobs in the app binary"),
}
}

View File

@@ -19,7 +19,7 @@ func TestToolCommandNames(t *testing.T) {
for _, c := range toolCommands() {
names = append(names, c.Name)
}
for _, want := range []string{"build", "make:plugin", "make:model", "make:migration", "make:command", "make:job", "make:admin-controller", "plugin:add", "dev", "migrate", "migrate:rollback", "migrate:status", "serve", "queue:work", "queue:clear"} {
for _, want := range []string{"build", "make:plugin", "make:model", "make:migration", "make:command", "make:job", "make:admin-controller", "plugin:add", "dev", "migrate", "migrate:rollback", "migrate:status", "serve", "queue:work", "queue:clear", "schedule:run"} {
if !slices.Contains(names, want) {
t.Fatalf("missing %s in %v", want, names)
}
@@ -32,6 +32,7 @@ func TestToolCommandNames(t *testing.T) {
"make:command": {"[plugin] [name]"},
"make:job": {"[plugin] [name]"},
"make:admin-controller": {"[plugin] [name]"},
"schedule:run": {"--once"},
}
for cmd, wants := range helpWants {
var buf bytes.Buffer

View File

@@ -6,10 +6,11 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/internal/build"
"git.golem15.com/golem15/summercms/modules/bonfire"
)
func delegateCommand(name, description string) bonfire.Command {
@@ -63,6 +64,28 @@ func delegateQueueWorkCommand() bonfire.Command {
}
}
func delegateScheduleRunCommand() bonfire.Command {
return bonfire.Command{
Name: "schedule:run",
Description: "Run the scheduler in the app binary (or once for system cron)",
Flags: []bonfire.Flag{{
Name: "once",
Description: "Run the entries due this minute and exit (for system cron)",
Bare: true,
}},
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
argv := []string{"schedule:run"}
if v, ok := in.Flag("once"); ok {
if once, _ := strconv.ParseBool(v); once {
argv = append(argv, "--once")
}
}
argv = append(argv, in.Args()...)
return runAppBinary(ctx, argv, out)
},
}
}
func runAppBinary(ctx context.Context, argv []string, out bonfire.Output) error {
if len(argv) == 0 {
return fmt.Errorf("summer: missing app command")