feat: support multiple workflow outputs

This commit is contained in:
Fu Diwei 2025-02-06 20:09:26 +08:00
parent d32fce98ae
commit 3f9fda8a2d
3 changed files with 10 additions and 23 deletions

View File

@ -81,7 +81,7 @@ func (n *applyNode) Run(ctx context.Context) error {
// 保存执行结果 // 保存执行结果
// TODO: 先保持一个节点始终只有一个输出,后续增加版本控制 // TODO: 先保持一个节点始终只有一个输出,后续增加版本控制
currentOutput := &domain.WorkflowOutput{ output := &domain.WorkflowOutput{
WorkflowId: getContextWorkflowId(ctx), WorkflowId: getContextWorkflowId(ctx),
RunId: getContextWorkflowRunId(ctx), RunId: getContextWorkflowRunId(ctx),
NodeId: n.node.Id, NodeId: n.node.Id,
@ -89,10 +89,7 @@ func (n *applyNode) Run(ctx context.Context) error {
Succeeded: true, Succeeded: true,
Outputs: n.node.Outputs, Outputs: n.node.Outputs,
} }
if lastOutput != nil { if _, err := n.outputRepo.SaveWithCertificate(ctx, output, certificate); err != nil {
currentOutput.Id = lastOutput.Id
}
if _, err := n.outputRepo.SaveWithCertificate(ctx, currentOutput, certificate); err != nil {
n.AddOutput(ctx, n.node.Name, "保存申请记录失败", err.Error()) n.AddOutput(ctx, n.node.Name, "保存申请记录失败", err.Error())
return err return err
} }
@ -127,7 +124,7 @@ func (n *applyNode) checkCanSkip(ctx context.Context, lastOutput *domain.Workflo
renewalInterval := time.Duration(currentNodeConfig.SkipBeforeExpiryDays) * time.Hour * 24 renewalInterval := time.Duration(currentNodeConfig.SkipBeforeExpiryDays) * time.Hour * 24
expirationTime := time.Until(lastCertificate.ExpireAt) expirationTime := time.Until(lastCertificate.ExpireAt)
if expirationTime > renewalInterval { if expirationTime > renewalInterval {
return true, fmt.Sprintf("已申请过证书,且证书尚未临近过期(到期尚余 %d 天,预计 %d 天时续期)", int(expirationTime.Hours()/24), currentNodeConfig.SkipBeforeExpiryDays) return true, fmt.Sprintf("已申请过证书,且证书尚未临近过期(到期尚余 %d 天,预计不足 %d 天时续期)", int(expirationTime.Hours()/24), currentNodeConfig.SkipBeforeExpiryDays)
} }
} }
} }

View File

@ -53,13 +53,11 @@ func (n *deployNode) Run(ctx context.Context) error {
} }
// 检测是否可以跳过本次执行 // 检测是否可以跳过本次执行
if skippable, skipReason := n.checkCanSkip(ctx, lastOutput); skippable { if certificate.CreatedAt.Before(lastOutput.UpdatedAt) {
if certificate.CreatedAt.Before(lastOutput.UpdatedAt) { if skippable, skipReason := n.checkCanSkip(ctx, lastOutput); skippable {
n.AddOutput(ctx, n.node.Name, "已部署过且证书未更新")
} else {
n.AddOutput(ctx, n.node.Name, skipReason) n.AddOutput(ctx, n.node.Name, skipReason)
return nil
} }
return nil
} }
// 初始化部署器 // 初始化部署器
@ -80,18 +78,14 @@ func (n *deployNode) Run(ctx context.Context) error {
n.AddOutput(ctx, n.node.Name, "部署成功") n.AddOutput(ctx, n.node.Name, "部署成功")
// 保存执行结果 // 保存执行结果
// TODO: 先保持一个节点始终只有一个输出,后续增加版本控制 output := &domain.WorkflowOutput{
currentOutput := &domain.WorkflowOutput{
WorkflowId: getContextWorkflowId(ctx), WorkflowId: getContextWorkflowId(ctx),
RunId: getContextWorkflowRunId(ctx), RunId: getContextWorkflowRunId(ctx),
NodeId: n.node.Id, NodeId: n.node.Id,
Node: n.node, Node: n.node,
Succeeded: true, Succeeded: true,
} }
if lastOutput != nil { if _, err := n.outputRepo.Save(ctx, output); err != nil {
currentOutput.Id = lastOutput.Id
}
if _, err := n.outputRepo.Save(ctx, currentOutput); err != nil {
n.AddOutput(ctx, n.node.Name, "保存部署记录失败", err.Error()) n.AddOutput(ctx, n.node.Name, "保存部署记录失败", err.Error())
return err return err
} }

View File

@ -68,8 +68,7 @@ func (n *uploadNode) Run(ctx context.Context) error {
certificate.PopulateFromPEM(nodeConfig.Certificate, nodeConfig.PrivateKey) certificate.PopulateFromPEM(nodeConfig.Certificate, nodeConfig.PrivateKey)
// 保存执行结果 // 保存执行结果
// TODO: 先保持一个节点始终只有一个输出,后续增加版本控制 output := &domain.WorkflowOutput{
currentOutput := &domain.WorkflowOutput{
WorkflowId: getContextWorkflowId(ctx), WorkflowId: getContextWorkflowId(ctx),
RunId: getContextWorkflowRunId(ctx), RunId: getContextWorkflowRunId(ctx),
NodeId: n.node.Id, NodeId: n.node.Id,
@ -77,10 +76,7 @@ func (n *uploadNode) Run(ctx context.Context) error {
Succeeded: true, Succeeded: true,
Outputs: n.node.Outputs, Outputs: n.node.Outputs,
} }
if lastOutput != nil { if _, err := n.outputRepo.SaveWithCertificate(ctx, output, certificate); err != nil {
currentOutput.Id = lastOutput.Id
}
if _, err := n.outputRepo.SaveWithCertificate(ctx, currentOutput, certificate); err != nil {
n.AddOutput(ctx, n.node.Name, "保存上传记录失败", err.Error()) n.AddOutput(ctx, n.node.Name, "保存上传记录失败", err.Error())
return err return err
} }