From 9b3c7e16c0bffc1b755ec4a34ccb5897bcb5bbd5 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Mon, 9 Jun 2025 21:34:03 +0800 Subject: [PATCH] fix: #769 --- internal/repository/certificate.go | 20 +++++++++++++++++++ .../workflow/node-processor/apply_node.go | 4 ++-- internal/workflow/node-processor/processor.go | 1 + .../workflow/node-processor/upload_node.go | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/internal/repository/certificate.go b/internal/repository/certificate.go index f5a345c7..1d2897bf 100644 --- a/internal/repository/certificate.go +++ b/internal/repository/certificate.go @@ -77,6 +77,26 @@ func (r *CertificateRepository) GetByWorkflowNodeId(ctx context.Context, workflo return r.castRecordToModel(records[0]) } +func (r *CertificateRepository) GetByWorkflowRunIdAndNodeId(ctx context.Context, workflowRunId string, workflowNodeId string) (*domain.Certificate, error) { + records, err := app.GetApp().FindRecordsByFilter( + domain.CollectionNameCertificate, + "workflowRunId={:workflowRunId} && workflowNodeId={:workflowNodeId} && deleted=null", + "-created", + 1, 0, + dbx.Params{"workflowRunId": workflowRunId}, + dbx.Params{"workflowNodeId": workflowNodeId}, + ) + if err != nil { + return nil, err + } + + if len(records) == 0 { + return nil, domain.ErrRecordNotFound + } + + return r.castRecordToModel(records[0]) +} + func (r *CertificateRepository) Save(ctx context.Context, certificate *domain.Certificate) (*domain.Certificate, error) { collection, err := app.GetApp().FindCollectionByNameOrId(domain.CollectionNameCertificate) if err != nil { diff --git a/internal/workflow/node-processor/apply_node.go b/internal/workflow/node-processor/apply_node.go index 313d21a6..c44c302b 100644 --- a/internal/workflow/node-processor/apply_node.go +++ b/internal/workflow/node-processor/apply_node.go @@ -105,7 +105,7 @@ func (n *applyNode) Process(ctx context.Context) error { // 保存 ARI 记录 if applyResult.ARIReplaced && lastOutput != nil { - lastCertificate, _ := n.certRepo.GetByWorkflowNodeId(ctx, lastOutput.NodeId) + lastCertificate, _ := n.certRepo.GetByWorkflowRunIdAndNodeId(ctx, lastOutput.RunId, lastOutput.NodeId) if lastCertificate != nil { lastCertificate.ACMERenewed = true n.certRepo.Save(ctx, lastCertificate) @@ -155,7 +155,7 @@ func (n *applyNode) checkCanSkip(ctx context.Context, lastOutput *domain.Workflo return false, "the configuration item 'KeyAlgorithm' changed" } - lastCertificate, _ := n.certRepo.GetByWorkflowNodeId(ctx, lastOutput.NodeId) + lastCertificate, _ := n.certRepo.GetByWorkflowRunIdAndNodeId(ctx, lastOutput.RunId, lastOutput.NodeId) if lastCertificate != nil { renewalInterval := time.Duration(thisNodeCfg.SkipBeforeExpiryDays) * time.Hour * 24 expirationTime := time.Until(lastCertificate.ExpireAt) diff --git a/internal/workflow/node-processor/processor.go b/internal/workflow/node-processor/processor.go index ec0a1d91..fed8f98e 100644 --- a/internal/workflow/node-processor/processor.go +++ b/internal/workflow/node-processor/processor.go @@ -50,6 +50,7 @@ func (n *nodeOutputer) GetOutputs() map[string]any { type certificateRepository interface { GetByWorkflowNodeId(ctx context.Context, workflowNodeId string) (*domain.Certificate, error) + GetByWorkflowRunIdAndNodeId(ctx context.Context, workflowRunId string, workflowNodeId string) (*domain.Certificate, error) Save(ctx context.Context, certificate *domain.Certificate) (*domain.Certificate, error) } diff --git a/internal/workflow/node-processor/upload_node.go b/internal/workflow/node-processor/upload_node.go index 95aac51d..053af435 100644 --- a/internal/workflow/node-processor/upload_node.go +++ b/internal/workflow/node-processor/upload_node.go @@ -93,7 +93,7 @@ func (n *uploadNode) checkCanSkip(ctx context.Context, lastOutput *domain.Workfl return false, "the configuration item 'PrivateKey' changed" } - lastCertificate, _ := n.certRepo.GetByWorkflowNodeId(ctx, lastOutput.NodeId) + lastCertificate, _ := n.certRepo.GetByWorkflowRunIdAndNodeId(ctx, lastOutput.RunId, lastOutput.NodeId) if lastCertificate != nil { daysLeft := int(time.Until(lastCertificate.ExpireAt).Hours() / 24) n.outputs[outputKeyForCertificateValidity] = strconv.FormatBool(daysLeft > 0)