mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 05:29:51 +00:00
feat: support multiple workflow outputs
This commit is contained in:
parent
d32fce98ae
commit
3f9fda8a2d
@ -81,7 +81,7 @@ func (n *applyNode) Run(ctx context.Context) error {
|
||||
|
||||
// 保存执行结果
|
||||
// TODO: 先保持一个节点始终只有一个输出,后续增加版本控制
|
||||
currentOutput := &domain.WorkflowOutput{
|
||||
output := &domain.WorkflowOutput{
|
||||
WorkflowId: getContextWorkflowId(ctx),
|
||||
RunId: getContextWorkflowRunId(ctx),
|
||||
NodeId: n.node.Id,
|
||||
@ -89,10 +89,7 @@ func (n *applyNode) Run(ctx context.Context) error {
|
||||
Succeeded: true,
|
||||
Outputs: n.node.Outputs,
|
||||
}
|
||||
if lastOutput != nil {
|
||||
currentOutput.Id = lastOutput.Id
|
||||
}
|
||||
if _, err := n.outputRepo.SaveWithCertificate(ctx, currentOutput, certificate); err != nil {
|
||||
if _, err := n.outputRepo.SaveWithCertificate(ctx, output, certificate); err != nil {
|
||||
n.AddOutput(ctx, n.node.Name, "保存申请记录失败", err.Error())
|
||||
return err
|
||||
}
|
||||
@ -127,7 +124,7 @@ func (n *applyNode) checkCanSkip(ctx context.Context, lastOutput *domain.Workflo
|
||||
renewalInterval := time.Duration(currentNodeConfig.SkipBeforeExpiryDays) * time.Hour * 24
|
||||
expirationTime := time.Until(lastCertificate.ExpireAt)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,14 +53,12 @@ func (n *deployNode) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// 检测是否可以跳过本次执行
|
||||
if skippable, skipReason := n.checkCanSkip(ctx, lastOutput); skippable {
|
||||
if certificate.CreatedAt.Before(lastOutput.UpdatedAt) {
|
||||
n.AddOutput(ctx, n.node.Name, "已部署过且证书未更新")
|
||||
} else {
|
||||
if skippable, skipReason := n.checkCanSkip(ctx, lastOutput); skippable {
|
||||
n.AddOutput(ctx, n.node.Name, skipReason)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化部署器
|
||||
deployer, err := deployer.NewWithDeployNode(n.node, struct {
|
||||
@ -80,18 +78,14 @@ func (n *deployNode) Run(ctx context.Context) error {
|
||||
n.AddOutput(ctx, n.node.Name, "部署成功")
|
||||
|
||||
// 保存执行结果
|
||||
// TODO: 先保持一个节点始终只有一个输出,后续增加版本控制
|
||||
currentOutput := &domain.WorkflowOutput{
|
||||
output := &domain.WorkflowOutput{
|
||||
WorkflowId: getContextWorkflowId(ctx),
|
||||
RunId: getContextWorkflowRunId(ctx),
|
||||
NodeId: n.node.Id,
|
||||
Node: n.node,
|
||||
Succeeded: true,
|
||||
}
|
||||
if lastOutput != nil {
|
||||
currentOutput.Id = lastOutput.Id
|
||||
}
|
||||
if _, err := n.outputRepo.Save(ctx, currentOutput); err != nil {
|
||||
if _, err := n.outputRepo.Save(ctx, output); err != nil {
|
||||
n.AddOutput(ctx, n.node.Name, "保存部署记录失败", err.Error())
|
||||
return err
|
||||
}
|
||||
|
@ -68,8 +68,7 @@ func (n *uploadNode) Run(ctx context.Context) error {
|
||||
certificate.PopulateFromPEM(nodeConfig.Certificate, nodeConfig.PrivateKey)
|
||||
|
||||
// 保存执行结果
|
||||
// TODO: 先保持一个节点始终只有一个输出,后续增加版本控制
|
||||
currentOutput := &domain.WorkflowOutput{
|
||||
output := &domain.WorkflowOutput{
|
||||
WorkflowId: getContextWorkflowId(ctx),
|
||||
RunId: getContextWorkflowRunId(ctx),
|
||||
NodeId: n.node.Id,
|
||||
@ -77,10 +76,7 @@ func (n *uploadNode) Run(ctx context.Context) error {
|
||||
Succeeded: true,
|
||||
Outputs: n.node.Outputs,
|
||||
}
|
||||
if lastOutput != nil {
|
||||
currentOutput.Id = lastOutput.Id
|
||||
}
|
||||
if _, err := n.outputRepo.SaveWithCertificate(ctx, currentOutput, certificate); err != nil {
|
||||
if _, err := n.outputRepo.SaveWithCertificate(ctx, output, certificate); err != nil {
|
||||
n.AddOutput(ctx, n.node.Name, "保存上传记录失败", err.Error())
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user