mirror of
https://github.com/certimate-go/certimate.git
synced 2026-06-19 21:03:27 +08:00
refactor: clean code
This commit is contained in:
parent
098a8d8987
commit
c37cb4afba
@ -4,7 +4,6 @@ import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@ -49,12 +48,11 @@ func (s *CertificateService) InitSchedule(ctx context.Context) error {
|
||||
return
|
||||
}
|
||||
|
||||
var settingsContent *domain.SettingsContentAsPersistence
|
||||
json.Unmarshal([]byte(settings.Content), &settingsContent)
|
||||
if settingsContent != nil && settingsContent.ExpiredCertificatesMaxDaysRetention != 0 {
|
||||
persistenceSettings, _ := settings.UnmarshalContentAsPersistence()
|
||||
if persistenceSettings != nil && persistenceSettings.ExpiredCertificatesMaxDaysRetention != 0 {
|
||||
ret, err := s.certificateRepo.DeleteWhere(
|
||||
context.Background(),
|
||||
dbx.NewExp(fmt.Sprintf("validityNotAfter<DATETIME('now', '-%d days')", settingsContent.ExpiredCertificatesMaxDaysRetention)),
|
||||
dbx.NewExp(fmt.Sprintf("validityNotAfter<DATETIME('now', '-%d days')", persistenceSettings.ExpiredCertificatesMaxDaysRetention)),
|
||||
)
|
||||
if err != nil {
|
||||
app.GetLogger().Error("failed to delete expired certificates", "err", err)
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package domain
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
const CollectionNameSettings = "settings"
|
||||
|
||||
type Settings struct {
|
||||
@ -12,3 +14,11 @@ type SettingsContentAsPersistence struct {
|
||||
WorkflowRunsMaxDaysRetention int `json:"workflowRunsMaxDaysRetention"`
|
||||
ExpiredCertificatesMaxDaysRetention int `json:"expiredCertificatesMaxDaysRetention"`
|
||||
}
|
||||
|
||||
func (s *Settings) UnmarshalContentAsPersistence() (*SettingsContentAsPersistence, error) {
|
||||
var content *SettingsContentAsPersistence
|
||||
if err := json.Unmarshal([]byte(s.Content), &content); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return content, nil
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package workflow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@ -59,14 +58,13 @@ func (s *WorkflowService) InitSchedule(ctx context.Context) error {
|
||||
return
|
||||
}
|
||||
|
||||
var settingsContent *domain.SettingsContentAsPersistence
|
||||
json.Unmarshal([]byte(settings.Content), &settingsContent)
|
||||
if settingsContent != nil && settingsContent.WorkflowRunsMaxDaysRetention != 0 {
|
||||
persistenceSettings, _ := settings.UnmarshalContentAsPersistence()
|
||||
if persistenceSettings != nil && persistenceSettings.WorkflowRunsMaxDaysRetention != 0 {
|
||||
ret, err := s.workflowRunRepo.DeleteWhere(
|
||||
context.Background(),
|
||||
dbx.NewExp(fmt.Sprintf("status!='%s'", string(domain.WorkflowRunStatusTypePending))),
|
||||
dbx.NewExp(fmt.Sprintf("status!='%s'", string(domain.WorkflowRunStatusTypeRunning))),
|
||||
dbx.NewExp(fmt.Sprintf("endedAt<DATETIME('now', '-%d days')", settingsContent.WorkflowRunsMaxDaysRetention)),
|
||||
dbx.NewExp(fmt.Sprintf("endedAt<DATETIME('now', '-%d days')", persistenceSettings.WorkflowRunsMaxDaysRetention)),
|
||||
)
|
||||
if err != nil {
|
||||
app.GetLogger().Error("failed to delete workflow history runs", "err", err)
|
||||
|
||||
@ -52,13 +52,13 @@ const Dashboard = () => {
|
||||
<Card className="transition-all max-lg:flex-1 lg:w-[280px] xl:w-[360px]" title={t("dashboard.quick_actions")}>
|
||||
<div className="flex flex-col gap-4">
|
||||
<Button block type="primary" size="large" icon={<IconCirclePlus size="1.25em" />} onClick={() => navigate("/workflows/new")}>
|
||||
{t("dashboard.quick_actions.create_workflow")}
|
||||
<span className="text-sm">{t("dashboard.quick_actions.create_workflow")}</span>
|
||||
</Button>
|
||||
<Button block size="large" icon={<IconLock size="1.25em" />} onClick={() => navigate("/settings/account")}>
|
||||
{t("dashboard.quick_actions.change_password")}
|
||||
<span className="text-sm">{t("dashboard.quick_actions.change_password")}</span>
|
||||
</Button>
|
||||
<Button block size="large" icon={<IconPlugConnected size="1.25em" />} onClick={() => navigate("/settings/ssl-provider")}>
|
||||
{t("dashboard.quick_actions.configure_ca")}
|
||||
<span className="text-sm">{t("dashboard.quick_actions.configure_ca")}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user