mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 01:36:37 +08:00
autoresearch iter 17: wire the pairing-code cleanup cron to a real handler
message_gateway scheduled message_gateway:cleanup_pairing_codes every 10 minutes but never registered a task under that pattern, so every dispatch went to a task type with no handler and expired pairing rows accumulated forever, even though repository.DeleteExpiredPairingCodes already existed. Add a test that fails for any schedule whose task pattern is unregistered: it reports the exact orphan rather than relying on a schedule-exists assert.
This commit is contained in:
@@ -154,6 +154,10 @@ func (p *Plugin) Apply(ctx *core.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ctx.Task().Register("message_gateway:cleanup_pairing_codes", func(c context.Context, _ []byte) error {
|
||||||
|
return repository.DeleteExpiredPairingCodes(c)
|
||||||
|
}, extpoints.WithTaskRetry(defaultTaskRetry))
|
||||||
|
|
||||||
// 6. Register Cron Schedules
|
// 6. Register Cron Schedules
|
||||||
ctx.Schedule().RegisterCron("*/10 * * * *", "message_gateway:cleanup_pairing_codes", map[string]any{"action": "cleanup"})
|
ctx.Schedule().RegisterCron("*/10 * * * *", "message_gateway:cleanup_pairing_codes", map[string]any{"action": "cleanup"})
|
||||||
|
|
||||||
|
|||||||
@@ -43,3 +43,19 @@ func TestMessageGatewayPluginUnit(t *testing.T) {
|
|||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
assert.Equal(t, 5, setting.Default)
|
assert.Equal(t, 5, setting.Default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestEveryScheduleHasTaskHandler 回归:RegisterCron 仅登记调度;若同名任务从未
|
||||||
|
// Register,则每次触发都投递到无人处理的任务类型,清理逻辑静默失效。
|
||||||
|
func TestEveryScheduleHasTaskHandler(t *testing.T) {
|
||||||
|
ctx := core.NewContext(context.Background())
|
||||||
|
require.NoError(t, message_gateway.New().Apply(ctx))
|
||||||
|
|
||||||
|
schedules := ctx.Schedules().Schedules()
|
||||||
|
require.NotEmpty(t, schedules)
|
||||||
|
|
||||||
|
for _, sched := range schedules {
|
||||||
|
_, ok := ctx.Tasks().Get(sched.TaskType)
|
||||||
|
assert.Truef(t, ok, "schedule %q dispatches to task %q, which is never registered",
|
||||||
|
sched.Spec, sched.TaskType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user