mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -248,6 +248,9 @@ func (c *Container) Boot() {
|
||||
// 启动调度器定时任务
|
||||
c.Scheduler.Start(c.stopCtx)
|
||||
|
||||
// 云盘存储健康检查
|
||||
c.BootCloudStorageHealthCheck(c.stopCtx)
|
||||
|
||||
// 自动扫描云盘媒体库,使内容对所有用户立即可见
|
||||
c.BootCloudLibraries(c.stopCtx)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user