diff --git a/service/CollectorService.go b/service/CollectorService.go index f6bfa93..64fd7f5 100644 --- a/service/CollectorService.go +++ b/service/CollectorService.go @@ -82,7 +82,7 @@ func (s *CollectorService) RemoveSensorConfigs(sensorConfigs []*ocmsc.SensorConf } for _, sensorConfig := range sensorConfigs { - s.scheduleMap.Delete(sensorConfig.ConfigID) + s.removeSchedule(sensorConfig.ConfigID) } return nil @@ -97,6 +97,15 @@ func (s *CollectorService) addSchedule(interval int64, sensorConfig *ocmsc.Senso s.scheduleMap.Store(sensorConfig.ConfigID, scheduleID) } +func (s *CollectorService) removeSchedule(configID string) { + scheduleID, ok := s.scheduleMap.Load(configID) + if !ok { + return + } + s.scheduleMap.Delete(configID) + s.scheduler.Cancel(scheduleID.(string)) +} + func (s *CollectorService) collectTask(sensorConfig *ocmsc.SensorConfig) { logging.Logger().Debugf("CollectorService.collectTask for sensor config id[%s] of crawler[%s]", sensorConfig.ConfigID, sensorConfig.Crawler.Name)