Files
miti99bot/internal/modules/cron_dispatcher.go
T
tiennm99 cc547136b7 refactor(server): drop HTTP /cron route; run crons in-process only
The in-process scheduler is the sole cron trigger on self-host, so the
/cron/{name} HTTP endpoint and its CRON_SHARED_SECRET are dead surface.
Reduce the HTTP server to GET / (health) and remove the cron secret config,
SSM binding, and now-unused timeout.
2026-06-28 22:15:04 +07:00

31 lines
1006 B
Go

package modules
import (
"context"
"errors"
"fmt"
)
// ErrCronNotFound is returned when name addresses an unregistered cron.
var ErrCronNotFound = errors.New("cron not found")
// DispatchScheduled runs the cron registered under name with the per-module
// prefixed Deps the registry stored at Build time. Returns ErrCronNotFound if
// no module owns that name — a scheduler firing an unknown name is a
// configuration bug worth surfacing to the caller.
//
// The handler runs synchronously in the calling goroutine; ctx propagates
// the scheduler's per-fire cancellation/timeout.
func DispatchScheduled(ctx context.Context, name string, reg *Registry) error {
cron, ok := reg.Cron(name)
if !ok {
return fmt.Errorf("%w: %q", ErrCronNotFound, name)
}
deps, ok := reg.CronDeps(name)
if !ok {
// Should be impossible: Build always co-registers cron and cronDeps.
return fmt.Errorf("modules: cron %q has no registered deps (registry corruption)", name)
}
return cron.Handler(ctx, deps)
}