Compare commits

...

7 Commits

Author SHA1 Message Date
RHQYZ
59dc4b0030
Merge 5da142ab83038e74711515071c32388b1fb607f5 into 1f6b33f4f6a3c2ed758a1294e5d51505394a90ec 2025-02-10 08:28:07 +00:00
Fu Diwei
5da142ab83 fix: memory leak 2025-02-10 16:27:01 +08:00
Fu Diwei
cbf711ee60 feat: save run logs when each workflow node completed 2025-02-10 16:19:04 +08:00
Yoan.liu
1f6b33f4f6 update version 2025-02-08 09:00:15 +08:00
Yoan.liu
049707acdc
Merge pull request #438 from hujingnb/fix/k8s_secret
fix: k8s secret not updated
2025-02-08 08:56:52 +08:00
hujing
e019bfe136 fix: k8s secret not updated 2025-01-31 00:50:40 +08:00
Yoan.liu
57f8db010b
Merge pull request #433 from fudiwei/feat/new-workflow
feat: more providers
2025-01-24 10:26:30 +08:00
11 changed files with 50 additions and 23 deletions

View File

@ -55,8 +55,8 @@ type WorkflowNode struct {
Inputs []WorkflowNodeIO `json:"inputs"` Inputs []WorkflowNodeIO `json:"inputs"`
Outputs []WorkflowNodeIO `json:"outputs"` Outputs []WorkflowNodeIO `json:"outputs"`
Next *WorkflowNode `json:"next"` Next *WorkflowNode `json:"next,omitempty"`
Branches []WorkflowNode `json:"branches"` Branches []WorkflowNode `json:"branches,omitempty"`
Validated bool `json:"validated"` Validated bool `json:"validated"`
} }

View File

@ -131,6 +131,11 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context, certPem string, privkeyP
secretPayload.ObjectMeta.Annotations[k] = v secretPayload.ObjectMeta.Annotations[k] = v
} }
} }
if secretPayload.Data == nil {
secretPayload.Data = make(map[string][]byte)
}
secretPayload.Data[d.config.SecretDataKeyForCrt] = []byte(certPem)
secretPayload.Data[d.config.SecretDataKeyForKey] = []byte(privkeyPem)
secretPayload, err = client.CoreV1().Secrets(d.config.Namespace).Update(context.TODO(), secretPayload, k8sMeta.UpdateOptions{}) secretPayload, err = client.CoreV1().Secrets(d.config.Namespace).Update(context.TODO(), secretPayload, k8sMeta.UpdateOptions{})
if err != nil { if err != nil {
return nil, xerrors.Wrap(err, "failed to update k8s secret") return nil, xerrors.Wrap(err, "failed to update k8s secret")

View File

@ -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 runErr := invoker.Invoke(ctx); runErr != nil {
if errors.Is(runErr, context.Canceled) { if errors.Is(runErr, context.Canceled) {
run.Status = domain.WorkflowRunStatusTypeCanceled run.Status = domain.WorkflowRunStatusTypeCanceled

View File

@ -13,18 +13,23 @@ type workflowInvoker struct {
workflowContent *domain.WorkflowNode workflowContent *domain.WorkflowNode
runId string runId string
runLogs []domain.WorkflowRunLog runLogs []domain.WorkflowRunLog
workflowRunRepo workflowRunRepository
} }
func newWorkflowInvoker(data *WorkflowWorkerData) *workflowInvoker { func newWorkflowInvokerWithData(workflowRunRepo workflowRunRepository, data *WorkflowWorkerData) *workflowInvoker {
if data == nil { if data == nil {
panic("worker data is nil") panic("worker data is nil")
} }
// TODO: 待优化,日志与执行解耦
return &workflowInvoker{ return &workflowInvoker{
workflowId: data.WorkflowId, workflowId: data.WorkflowId,
workflowContent: data.WorkflowContent, workflowContent: data.WorkflowContent,
runId: data.RunId, runId: data.RunId,
runLogs: make([]domain.WorkflowRunLog, 0), 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) log := processor.GetLog(ctx)
if log != nil { if log != nil {
w.runLogs = append(w.runLogs, *log) 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 { if procErr != nil {
break break

View File

@ -23,6 +23,7 @@ var (
) )
func GetSingletonDispatcher(workflowRepo workflowRepository, workflowRunRepo workflowRunRepository) *WorkflowDispatcher { func GetSingletonDispatcher(workflowRepo workflowRepository, workflowRunRepo workflowRunRepository) *WorkflowDispatcher {
// TODO: 待优化构造过程
intanceOnce.Do(func() { intanceOnce.Do(func() {
instance = newWorkflowDispatcher(workflowRepo, workflowRunRepo) instance = newWorkflowDispatcher(workflowRepo, workflowRunRepo)
}) })

View File

@ -55,6 +55,7 @@ func (l *nodeLogger) AppendLogRecord(ctx context.Context, level domain.WorkflowR
} }
if len(err) > 0 { if len(err) > 0 {
record.Error = err[0] record.Error = err[0]
l.log.Error = err[0]
} }
l.log.Records = append(l.log.Records, record) l.log.Records = append(l.log.Records, record)

View File

@ -32,7 +32,9 @@ const WorkflowRunDetail = ({ data, ...props }: WorkflowRunDetailProps) => {
<Alert showIcon type="error" message={<Typography.Text type="danger">{t("workflow_run.props.status.failed")}</Typography.Text>} /> <Alert showIcon type="error" message={<Typography.Text type="danger">{t("workflow_run.props.status.failed")}</Typography.Text>} />
</Show> </Show>
<div className="my-4 rounded-md bg-black p-4 text-stone-200"> <div className="my-4">
<Typography.Title level={5}>{t("workflow_run.logs")}</Typography.Title>
<div className="rounded-md bg-black p-4 text-stone-200">
<div className="flex flex-col space-y-4"> <div className="flex flex-col space-y-4">
{data.logs?.map((item, i) => { {data.logs?.map((item, i) => {
return ( return (
@ -53,6 +55,7 @@ const WorkflowRunDetail = ({ data, ...props }: WorkflowRunDetailProps) => {
})} })}
</div> </div>
</div> </div>
</div>
<Show when={data.status === WORKFLOW_RUN_STATUSES.SUCCEEDED}> <Show when={data.status === WORKFLOW_RUN_STATUSES.SUCCEEDED}>
<Divider /> <Divider />

View File

@ -227,6 +227,10 @@ const WorkflowRuns = ({ className, style, workflowId }: WorkflowRunsProps) => {
} }
return [...prev]; return [...prev];
}); });
if (cb.record.status !== WORKFLOW_RUN_STATUSES.PENDING && cb.record.status !== WORKFLOW_RUN_STATUSES.RUNNING) {
unsubscribeWorkflowRun(item.id);
}
}); });
} }

View File

@ -1 +1 @@
export const version = "v0.3.0-alpha.10"; export const version = "v0.3.0-alpha.11";

View File

@ -18,6 +18,7 @@
"workflow_run.props.started_at": "Started at", "workflow_run.props.started_at": "Started at",
"workflow_run.props.ended_at": "Ended at", "workflow_run.props.ended_at": "Ended at",
"workflow_run.logs": "Logs",
"workflow_run.artifacts": "Artifacts", "workflow_run.artifacts": "Artifacts",
"workflow_run_artifact.props.type": "Type", "workflow_run_artifact.props.type": "Type",

View File

@ -18,6 +18,7 @@
"workflow_run.props.started_at": "开始时间", "workflow_run.props.started_at": "开始时间",
"workflow_run.props.ended_at": "完成时间", "workflow_run.props.ended_at": "完成时间",
"workflow_run.logs": "日志",
"workflow_run.artifacts": "输出产物", "workflow_run.artifacts": "输出产物",
"workflow_run_artifact.props.type": "类型", "workflow_run_artifact.props.type": "类型",