mirror of
https://github.com/usual2970/certimate.git
synced 2025-10-05 22:14:53 +00:00
feat: auto cleanup workflow history runs and expired certificates
This commit is contained in:
@@ -67,11 +67,9 @@ func (r *CertificateRepository) GetByWorkflowNodeId(ctx context.Context, workflo
|
||||
dbx.Params{"workflowNodeId": workflowNodeId},
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrRecordNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(records) == 0 {
|
||||
return nil, domain.ErrRecordNotFound
|
||||
}
|
||||
@@ -125,6 +123,29 @@ func (r *CertificateRepository) Save(ctx context.Context, certificate *domain.Ce
|
||||
return certificate, nil
|
||||
}
|
||||
|
||||
func (r *CertificateRepository) DeleteWhere(ctx context.Context, exprs ...dbx.Expression) (int, error) {
|
||||
records, err := app.GetApp().FindAllRecords(domain.CollectionNameCertificate, exprs...)
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var ret int
|
||||
var errs []error
|
||||
for _, record := range records {
|
||||
if err := app.GetApp().Delete(record); err != nil {
|
||||
errs = append(errs, err)
|
||||
} else {
|
||||
ret++
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
return ret, errors.Join(errs...)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (r *CertificateRepository) castRecordToModel(record *core.Record) (*domain.Certificate, error) {
|
||||
if record == nil {
|
||||
return nil, fmt.Errorf("record is nil")
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/usual2970/certimate/internal/app"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
@@ -96,6 +97,29 @@ func (r *WorkflowRunRepository) Save(ctx context.Context, workflowRun *domain.Wo
|
||||
return workflowRun, nil
|
||||
}
|
||||
|
||||
func (r *WorkflowRunRepository) DeleteWhere(ctx context.Context, exprs ...dbx.Expression) (int, error) {
|
||||
records, err := app.GetApp().FindAllRecords(domain.CollectionNameWorkflowRun, exprs...)
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var ret int
|
||||
var errs []error
|
||||
for _, record := range records {
|
||||
if err := app.GetApp().Delete(record); err != nil {
|
||||
errs = append(errs, err)
|
||||
} else {
|
||||
ret++
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
return ret, errors.Join(errs...)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (r *WorkflowRunRepository) castRecordToModel(record *core.Record) (*domain.WorkflowRun, error) {
|
||||
if record == nil {
|
||||
return nil, fmt.Errorf("record is nil")
|
||||
|
Reference in New Issue
Block a user