mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-11 03:13:46 +00:00
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.
31 lines
1002 B
Go
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)
|
|
}
|