feat(续期): 启用定时静默续期与失败告警
默认每四小时执行 API Cookie 续期,账号间错峰一分钟;记录全部续期结果,并在同一账号连续三次失败时发送续期告警。
This commit is contained in:
1 parent
090802e25d
commit
cef2ca92c4
4 files changed
+98
-10
No files matched your search
@@ -261,6 +261,29 @@ func (r *RenewalStore) AddAPICookieRenewLog(ctx context.Context, log RenewalLog)
|
||||
return err
|
||||
}
|
||||
|
||||
// RecentAPICookieRenewStatuses 返回账号最近的 API Cookie 续期状态,最新记录在前。
|
||||
func (r *RenewalStore) RecentAPICookieRenewStatuses(ctx context.Context, cookieID string, limit int) ([]string, error) {
|
||||
if limit <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
rows, err := r.DB.QueryContext(ctx,
|
||||
`SELECT status FROM scheduled_api_cookie_renew_log
|
||||
WHERE cookie_id=? ORDER BY id DESC LIMIT ?`, cookieID, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
statuses := make([]string, 0, limit)
|
||||
for rows.Next() {
|
||||
var status string
|
||||
if err := rows.Scan(&status); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
statuses = append(statuses, status)
|
||||
}
|
||||
return statuses, rows.Err()
|
||||
}
|
||||
|
||||
// CleanupLogs deletes renewal logs older than retentionDays. Non-positive values skip cleanup.
|
||||
func (r *RenewalStore) CleanupLogs(ctx context.Context, retentionDays int) error {
|
||||
if retentionDays <= 0 {
|
||||
|
||||
Reference in new issue
Block a user