Exemplo n.º 1
0
func (srvMngr *ServiceManager) StartScheduler(waitCache bool) error {
	srvMngr.RLock()
	schedRunning := srvMngr.sched != nil
	srvMngr.RUnlock()
	if schedRunning {
		return utils.NewCGRError(utils.ServiceManager,
			utils.CapitalizedMessage(utils.ServiceAlreadyRunning),
			utils.ServiceAlreadyRunning,
			"the scheduler is already running")
	}
	if waitCache { // Wait for cache to load data before starting
		cacheDone := <-srvMngr.cacheDoneChan
		srvMngr.cacheDoneChan <- cacheDone
	}
	utils.Logger.Info("<ServiceManager> Starting CGRateS Scheduler.")
	sched := scheduler.NewScheduler(srvMngr.ratingDB)
	srvMngr.Lock()
	srvMngr.sched = sched
	srvMngr.Unlock()
	go func() {
		sched.Loop()
		srvMngr.Lock()
		srvMngr.sched = nil // if we are after loop, the service is down
		srvMngr.Unlock()
		if srvMngr.cfg.SchedulerEnabled {
			srvMngr.engineShutdown <- true // shutdown engine since this service should be running
		}
	}()
	return nil
}
Exemplo n.º 2
0
func (srvMngr *ServiceManager) StopScheduler() error {
	var sched *scheduler.Scheduler
	srvMngr.Lock()
	if srvMngr.sched != nil {
		sched = srvMngr.sched
		srvMngr.sched = nil // optimize the lock and release here
	}
	srvMngr.Unlock()
	if sched == nil {
		return utils.NewCGRError(utils.ServiceManager,
			utils.CapitalizedMessage(utils.ServiceAlreadyRunning),
			utils.ServiceAlreadyRunning,
			"the scheduler is not running")
	}
	srvMngr.cfg.SchedulerEnabled = false
	sched.Shutdown()
	return nil
}