fix(task): execute dispatched jobs and persist run records

Asynq func handlers now go through ProcessTask so admin execution
rows leave pending. The in-process worker resolves admin type
identifiers and writes the same w_task_executions table. Remove
the no-op admin system_cleanup that shadowed the upload handler.
This commit is contained in:
ryan
2026-09-02 16:11:45 +08:00
parent 33f28ad671
commit 30bbe965bf
14 changed files with 530 additions and 82 deletions
+1 -16
View File
@@ -181,22 +181,7 @@ func (p *Plugin) Apply(ctx *core.Context) error {
return err
}, extpoints.WithTaskMeta(service.LogDBSwitchMeta))
ctx.Task().Register("admin:system_cleanup", func(_ context.Context, _ []byte) error {
return nil
},
extpoints.WithTaskType("system_cleanup"),
extpoints.WithTaskName("系统垃圾清理"),
extpoints.WithTaskDescription("定期清理未使用上传文件、历史推送记录和过期任务执行日志"),
extpoints.WithTaskCategory("maintenance"),
extpoints.WithTaskRetry(1),
extpoints.WithTaskQueue("default"),
extpoints.WithTaskRetryable(true),
)
// 3. Register Cron Schedules
ctx.Schedule().RegisterCron("0 4 * * *", "admin:system_cleanup", map[string]string{"type": "daily"})
// 4. Register Settings Schemas
// 3. Register Settings Schemas
ctx.Settings().Register(extpoints.SettingSchema{
Key: "admin.system_cleanup_cron",
Default: "0 4 * * *",
+1 -6
View File
@@ -33,14 +33,9 @@ func TestAdminPluginUnit(t *testing.T) {
assert.True(t, hasRobots, "admin plugin must register /robots.txt")
// Verify tasks
_, ok := ctx.Tasks().Get("admin:system_cleanup")
_, ok := ctx.Tasks().Get("logs:db_switch")
require.True(t, ok)
// Verify schedules
sched, ok := ctx.Schedules().Get("admin:system_cleanup")
require.True(t, ok)
assert.Equal(t, "0 4 * * *", sched.Spec)
// Verify settings
setting, ok := ctx.Settings().Get("admin.system_cleanup_cron")
require.True(t, ok)
+3 -6
View File
@@ -380,12 +380,9 @@ func TestAdminPlugin(t *testing.T) {
assert.True(t, hasTasks)
assert.True(t, hasConfigs)
// 2. Task & Schedule
_, ok := ctx.Tasks().Get("admin:system_cleanup")
// 2. Task
_, ok := ctx.Tasks().Get("logs:db_switch")
require.True(t, ok)
sched, ok := ctx.Schedules().Get("admin:system_cleanup")
require.True(t, ok)
assert.Equal(t, "0 4 * * *", sched.Spec)
// 3. Settings
schema, ok := ctx.Settings().Get("admin.system_cleanup_cron")
@@ -455,7 +452,7 @@ func TestAllDomainPluginsCombined(t *testing.T) {
// Verify total schedules registered
allSchedules := ctx.Schedules().Schedules()
assert.GreaterOrEqual(t, len(allSchedules), 2)
assert.GreaterOrEqual(t, len(allSchedules), 1)
// 每个调度指向的任务类型都必须已注册 Handler,否则触发时会投递到无人处理的
// 任务类型,预期的清理逻辑静默失效。