mirror of
https://github.com/usual2970/certimate.git
synced 2025-08-06 17:31:47 +00:00
feat: save run logs when each workflow node completed
This commit is contained in:
@@ -242,7 +242,7 @@ func (w *WorkflowDispatcher) work(ctx context.Context, data *WorkflowWorkerData)
|
||||
}
|
||||
|
||||
// 执行工作流
|
||||
invoker := newWorkflowInvoker(data)
|
||||
invoker := newWorkflowInvokerWithData(w.workflowRunRepo, data)
|
||||
if runErr := invoker.Invoke(ctx); runErr != nil {
|
||||
if errors.Is(runErr, context.Canceled) {
|
||||
run.Status = domain.WorkflowRunStatusTypeCanceled
|
||||
|
@@ -13,18 +13,23 @@ type workflowInvoker struct {
|
||||
workflowContent *domain.WorkflowNode
|
||||
runId string
|
||||
runLogs []domain.WorkflowRunLog
|
||||
|
||||
workflowRunRepo workflowRunRepository
|
||||
}
|
||||
|
||||
func newWorkflowInvoker(data *WorkflowWorkerData) *workflowInvoker {
|
||||
func newWorkflowInvokerWithData(workflowRunRepo workflowRunRepository, data *WorkflowWorkerData) *workflowInvoker {
|
||||
if data == nil {
|
||||
panic("worker data is nil")
|
||||
}
|
||||
|
||||
// TODO: 待优化,日志与执行解耦
|
||||
return &workflowInvoker{
|
||||
workflowId: data.WorkflowId,
|
||||
workflowContent: data.WorkflowContent,
|
||||
runId: data.RunId,
|
||||
runLogs: make([]domain.WorkflowRunLog, 0),
|
||||
|
||||
workflowRunRepo: workflowRunRepo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +75,12 @@ func (w *workflowInvoker) processNode(ctx context.Context, node *domain.Workflow
|
||||
log := processor.GetLog(ctx)
|
||||
if log != nil {
|
||||
w.runLogs = append(w.runLogs, *log)
|
||||
|
||||
// TODO: 待优化,把 /pkg/core/* 包下的输出写入到 DEBUG 级别的日志中
|
||||
if run, err := w.workflowRunRepo.GetById(ctx, w.runId); err == nil {
|
||||
run.Logs = w.runLogs
|
||||
w.workflowRunRepo.Save(ctx, run)
|
||||
}
|
||||
}
|
||||
if procErr != nil {
|
||||
break
|
||||
|
@@ -23,6 +23,7 @@ var (
|
||||
)
|
||||
|
||||
func GetSingletonDispatcher(workflowRepo workflowRepository, workflowRunRepo workflowRunRepository) *WorkflowDispatcher {
|
||||
// TODO: 待优化构造过程
|
||||
intanceOnce.Do(func() {
|
||||
instance = newWorkflowDispatcher(workflowRepo, workflowRunRepo)
|
||||
})
|
||||
|
@@ -55,6 +55,7 @@ func (l *nodeLogger) AppendLogRecord(ctx context.Context, level domain.WorkflowR
|
||||
}
|
||||
if len(err) > 0 {
|
||||
record.Error = err[0]
|
||||
l.log.Error = err[0]
|
||||
}
|
||||
|
||||
l.log.Records = append(l.log.Records, record)
|
||||
|
Reference in New Issue
Block a user