mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
refactor(scheduler): migrate outbox and model registry to scheduler-based execution
Replace internal goroutine-based timing loops with scheduler integration for SyncOutboxService and ModelRegistryService. Both services now expose RunOnce() methods called by the central scheduler instead of managing their own background loops. - Add Interval() and RunOnce() methods to SyncOutboxService - Add RefreshEvery() and RunOnce() methods to ModelRegistryService - Remove started flag from SyncOutboxService struct - Move scheduler.Start() after all services are initialized - Ensure initial model registry refresh before scheduler starts
This commit is contained in:
@@ -81,26 +81,23 @@ func NewModelRegistryService(db *gorm.DB, rdb *redis.Client, cfg ModelRegistryCo
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ModelRegistryService) Start(ctx context.Context) {
|
||||
func (s *ModelRegistryService) Enabled() bool {
|
||||
return s != nil && s.cfg.Enabled
|
||||
}
|
||||
|
||||
func (s *ModelRegistryService) RefreshEvery() time.Duration {
|
||||
if s == nil || s.cfg.RefreshEvery <= 0 {
|
||||
return 30 * time.Minute
|
||||
}
|
||||
return s.cfg.RefreshEvery
|
||||
}
|
||||
|
||||
// RunOnce triggers a single model registry refresh. Called by scheduler.
|
||||
func (s *ModelRegistryService) RunOnce(ctx context.Context) {
|
||||
if !s.cfg.Enabled {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
ticker := time.NewTicker(s.cfg.RefreshEvery)
|
||||
defer ticker.Stop()
|
||||
|
||||
// Best-effort initial refresh.
|
||||
_ = s.Refresh(ctx, "")
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
_ = s.Refresh(ctx, "")
|
||||
}
|
||||
}
|
||||
}()
|
||||
_ = s.Refresh(ctx, "")
|
||||
}
|
||||
|
||||
type ModelRegistryStatus struct {
|
||||
|
||||
Reference in New Issue
Block a user