Files
tiennm99bot/internal/modules/cron_dispatcher.go
T
tiennm99 cf620a257e docs: fix stale code comments and add missing package docs
Correct comments that described the retired webhook transport, a removed
/cron route, the old KV store and wrapper types, and behaviour that has since
changed; drop plan and review labels; reword two startup log lines that
overstated or misnamed what they report.
2026-09-30 14:19:01 +07:00

31 lines
1002 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 owning
// module's 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)
}