补齐证书任务创建人归属
传递已认证操作者上下文,关联证书任务审计,并同步四份整改清单进度。
This commit is contained in:
1 parent
4cf9fb6076
commit
5fecd05d46
8 files changed
+100
-5
No files matched your search
@@ -65,7 +65,8 @@ func (w *certificateTaskWorkflow) run(ctx context.Context, id, taskType, stage s
|
||||
task := repository.Task{
|
||||
ID: domain.NewID(), DomainID: id, TaskType: taskType,
|
||||
Status: "running", Stage: stage, Message: "正在执行证书工作流",
|
||||
StartedAt: &started, CreatedAt: started,
|
||||
OperatorID: repository.TaskOperatorFromContext(ctx),
|
||||
StartedAt: &started, CreatedAt: started,
|
||||
}
|
||||
if err := w.tasks.CreateTask(ctx, task); err != nil {
|
||||
return result, err
|
||||
@@ -84,7 +85,8 @@ func (w *certificateTaskWorkflow) run(ctx context.Context, id, taskType, stage s
|
||||
auditErr := w.audit.CreateAuditLog(finishCtx, repository.AuditLog{
|
||||
TaskID: task.ID,
|
||||
Action: taskType, ResourceType: "domain", ResourceID: id,
|
||||
Status: status, Message: message,
|
||||
OperatorID: task.OperatorID,
|
||||
Status: status, Message: message,
|
||||
})
|
||||
if auditErr != nil {
|
||||
status, message = certificateTaskOutcome(result, auditErr)
|
||||
@@ -99,7 +101,8 @@ func (w *certificateTaskWorkflow) run(ctx context.Context, id, taskType, stage s
|
||||
if err := w.audit.CreateAuditLog(taskCtx, repository.AuditLog{
|
||||
TaskID: task.ID,
|
||||
Action: taskType, ResourceType: "domain", ResourceID: id,
|
||||
Status: "running", Message: "开始执行证书工作流",
|
||||
OperatorID: task.OperatorID,
|
||||
Status: "running", Message: "开始执行证书工作流",
|
||||
}); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -92,6 +92,40 @@ func TestCertificateTasksRecordSuccessFailureAndCancellation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCertificateTasksRecordOperatorFromWorkflowContext(t *testing.T) {
|
||||
w, a := newCertificateTaskFixture(t)
|
||||
ctx := repository.WithTaskOperator(t.Context(), "operator-1")
|
||||
_, err := w.run(ctx, "task-domain", "certificate_validate", "certificate_validate", 1, 0, func(context.Context, string) (CertificateWorkflowResult, error) {
|
||||
return CertificateWorkflowResult{}, nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("带操作者的证书任务执行失败:%v", err)
|
||||
}
|
||||
items, err := a.Tasks.ListTasks(t.Context(), "task-domain", 10)
|
||||
if err != nil || len(items) != 1 || items[0].OperatorID != "operator-1" {
|
||||
t.Fatalf("任务创建人记录错误:%+v %v", items, err)
|
||||
}
|
||||
var operators []string
|
||||
rows, err := a.Database.DB.QueryContext(t.Context(), "SELECT operator_id FROM audit_logs WHERE task_id = ? ORDER BY created_at, id", items[0].ID)
|
||||
if err != nil {
|
||||
t.Fatalf("读取任务审计失败:%v", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var operator string
|
||||
if err := rows.Scan(&operator); err != nil {
|
||||
t.Fatalf("读取任务审计操作者失败:%v", err)
|
||||
}
|
||||
operators = append(operators, operator)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
t.Fatalf("遍历任务审计失败:%v", err)
|
||||
}
|
||||
if len(operators) != 2 || operators[0] != "operator-1" || operators[1] != "operator-1" {
|
||||
t.Fatalf("任务审计创建人记录错误:%v", operators)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCertificateTasksKeepRetriesInOneTask(t *testing.T) {
|
||||
w, a := newCertificateTaskFixture(t)
|
||||
calls := 0
|
||||
|
||||
Reference in new issue
Block a user