@@ -33,6 +33,9 @@ const (
3333 DomainList string = "domain_list"
3434 RecordList string = "record_list"
3535 RecordCertInfo string = "record_cert_info"
36+ // Cron Config Defaults
37+ DefaultDomainRecordSyncInterval = 30 // 默认域名记录同步间隔(秒)
38+ DefaultCertInfoSyncInterval = 3600 // 默认证书信息同步间隔(秒),24小时
3639)
3740
3841var (
@@ -49,9 +52,16 @@ type Account struct {
4952 SecretKey string `yaml:"secretKey"`
5053}
5154
55+ // CronConfig 定时任务配置
56+ type CronConfig struct {
57+ DomainRecordSyncInterval int `yaml:"domain_record_sync_interval"` // 域名记录同步间隔(秒)
58+ CertInfoSyncInterval int `yaml:"cert_info_sync_interval"` // 证书信息同步间隔(秒)
59+ }
60+
5261// Config 表示配置文件的结构
5362type Configuration struct {
54- CustomRecords []string `yaml:"custom_records"`
63+ CronConfig * CronConfig `yaml:"cron_config"`
64+ CustomRecords []string `yaml:"custom_records"`
5565 CloudProviders map [string ]struct {
5666 Accounts []map [string ]string `yaml:"accounts"`
5767 } `yaml:"cloud_providers"`
@@ -90,3 +100,24 @@ func InitCache() {
90100func GetID () string {
91101 return xid .New ().String ()
92102}
103+
104+ // GetCronConfig 获取定时任务配置,如果未配置则返回默认值
105+ func GetCronConfig () CronConfig {
106+ if Config .CronConfig == nil {
107+ return CronConfig {
108+ DomainRecordSyncInterval : DefaultDomainRecordSyncInterval ,
109+ CertInfoSyncInterval : DefaultCertInfoSyncInterval ,
110+ }
111+ }
112+
113+ config := * Config .CronConfig
114+ // 如果配置了但值为0或负数,使用默认值
115+ if config .DomainRecordSyncInterval <= 0 {
116+ config .DomainRecordSyncInterval = DefaultDomainRecordSyncInterval
117+ }
118+ if config .CertInfoSyncInterval <= 0 {
119+ config .CertInfoSyncInterval = DefaultCertInfoSyncInterval
120+ }
121+
122+ return config
123+ }
0 commit comments