fix(task): restore task metadata contract and type fields in task types api

This commit is contained in:
ryan
2026-08-29 12:22:51 +08:00
parent 49f9d1076f
commit ea97b64407
22 changed files with 704 additions and 133 deletions
+77 -3
View File
@@ -140,16 +140,90 @@ func (p *Plugin) Apply(ctx *core.Context) error {
}
}
const defaultUserTaskRetry = 3
const (
defaultUserTaskRetry = 3
paramTypeString = "string"
paramNameEmail = "email"
)
// 4. Register background tasks
ctx.Task().Register("user:send_email_code", func(_ context.Context, _ []byte) error {
return nil
}, extpoints.WithTaskRetry(defaultUserTaskRetry))
},
extpoints.WithTaskType("send_email_code"),
extpoints.WithTaskName("发送邮箱验证码"),
extpoints.WithTaskDescription("异步发送用户注册与验证邮箱验证码"),
extpoints.WithTaskCategory("user"),
extpoints.WithTaskRetry(defaultUserTaskRetry),
extpoints.WithTaskQueue("default"),
extpoints.WithTaskRetryable(true),
extpoints.WithTaskParams(
contracts.TaskParamDTO{
Name: paramNameEmail,
Label: "目标邮箱",
Type: paramTypeString,
Required: true,
Placeholder: "user@example.com",
Description: "接收验证码的目标邮箱",
},
contracts.TaskParamDTO{
Name: "code",
Label: "验证码",
Type: paramTypeString,
Required: true,
Placeholder: "123456",
Description: "6 位数字验证码",
},
),
)
ctx.Task().Register("mail:send", func(_ context.Context, _ []byte) error {
return nil
},
extpoints.WithTaskType("send_email"),
extpoints.WithTaskName("发送邮件"),
extpoints.WithTaskDescription("异步发送系统邮件"),
extpoints.WithTaskCategory("mail"),
extpoints.WithTaskRetry(defaultUserTaskRetry),
extpoints.WithTaskQueue("default"),
extpoints.WithTaskRetryable(true),
extpoints.WithTaskParams(
contracts.TaskParamDTO{
Name: "to",
Label: "接收邮箱 (To)",
Type: paramTypeString,
Required: true,
Placeholder: "receiver@example.com",
Description: "接收邮件的目标邮箱地址",
},
contracts.TaskParamDTO{
Name: "subject",
Label: "邮件主题 (Subject)",
Type: paramTypeString,
Required: true,
Placeholder: "请输入邮件主题",
Description: "发送邮件的主题标题",
},
contracts.TaskParamDTO{
Name: "body",
Label: "邮件内容 (Body)",
Type: "text",
Required: true,
Placeholder: "请输入邮件内容(支持 HTML格式)",
Description: "发送邮件的内容主体",
},
),
)
ctx.Task().Register("user:cleanup_inactive", func(_ context.Context, _ []byte) error {
return nil
})
},
extpoints.WithTaskType("cleanup_inactive_users"),
extpoints.WithTaskName("清理未激活用户"),
extpoints.WithTaskDescription("清理长期未激活的注册用户与临时凭据"),
extpoints.WithTaskCategory("user"),
extpoints.WithTaskQueue("default"),
)
// 5. Register Settings Schemas
ctx.Settings().Register(extpoints.SettingSchema{