feat: add cloud storage health check on startup

- Validate all enabled cloud storage configs at boot
- Ping each cloud provider to ensure connectivity
- Log health status for better diagnostics
- Help identify cloud storage configuration issues early
This commit is contained in:
ShukeBta
2026-06-11 12:54:26 +08:00
parent 95794f7bbc
commit 7ef4af6287
2 changed files with 57 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
package service
import (
"context"
"time"
"go.uber.org/zap"
)
// BootCloudStorageHealthCheck验证所有已配置的云盘存储在启动时是否可用
func (c *Container) BootCloudStorageHealthCheck(ctx context.Context) {
if c == nil || c.StorageCfg == nil {
return
}
configs, err := c.StorageCfg.List(ctx)
if err != nil {
c.Log.Warn("boot: cloud storage health check failed to list configs", zap.Error(err))
return
}
cloudConfigs := make([]StorageView, 0)
for _, cfg := range configs {
if cfg.Enabled && (cfg.Type == "quark" || cfg.Type == "cloud115" || cfg.Type == "clouddrive2" || cfg.Type == "openlist") {
cloudConfigs = append(cloudConfigs, cfg)
}
}
if len(cloudConfigs) == 0 {
c.Log.Info("boot: no enabled cloud storage configured")
return
}
c.Log.Info("boot: checking cloud storage health", zap.Int("count", len(cloudConfigs)))
for _, cfg := range cloudConfigs {
go func(typ string) {
checkCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
provider, err := c.StorageCfg.CloudProvider(checkCtx, typ)
if err != nil {
c.Log.Warn("boot: cloud storage unavailable", zap.String("type", typ), zap.Error(err))
return
}
if err := provider.Ping(checkCtx); err != nil {
c.Log.Warn("boot: cloud storage ping failed", zap.String("type", typ), zap.Error(err))
} else {
c.Log.Info("boot: cloud storage healthy", zap.String("type", typ))
}
}(cfg.Type)
}
}
+3
View File
@@ -248,6 +248,9 @@ func (c *Container) Boot() {
// 启动调度器定时任务
c.Scheduler.Start(c.stopCtx)
// 云盘存储健康检查
c.BootCloudStorageHealthCheck(c.stopCtx)
// 自动扫描云盘媒体库,使内容对所有用户立即可见
c.BootCloudLibraries(c.stopCtx)