當前位置: 首頁>>代碼示例>>Golang>>正文


Golang scheduler.NewScheduler函數代碼示例

本文整理匯總了Golang中github.com/cgrates/cgrates/scheduler.NewScheduler函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewScheduler函數的具體用法?Golang NewScheduler怎麽用?Golang NewScheduler使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewScheduler函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: StartScheduler

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
}
開發者ID:cgrates,項目名稱:cgrates,代碼行數:30,代碼來源:servmanager.go

示例2: startScheduler

func startScheduler(internalSchedulerChan chan *scheduler.Scheduler, ratingDb engine.RatingStorage, exitChan chan bool) {
	utils.Logger.Info("Starting CGRateS Scheduler.")
	sched := scheduler.NewScheduler()
	go reloadSchedulerSingnalHandler(sched, ratingDb)
	time.Sleep(1)
	internalSchedulerChan <- sched
	sched.LoadActionPlans(ratingDb)
	sched.Loop()
	exitChan <- true // Should not get out of loop though
}
開發者ID:henrylee2cn,項目名稱:cgrates,代碼行數:10,代碼來源:cgr-engine.go

示例3: TestExecuteActions3

func TestExecuteActions3(t *testing.T) {
	scheduler.NewScheduler(ratingDb3).Reload()
	time.Sleep(10 * time.Millisecond) // Give time to scheduler to topup the account
	if acnt, err := acntDb3.GetAccount("cgrates.org:12346"); err != nil {
		t.Error(err)
	} else if len(acnt.BalanceMap) != 1 {
		t.Error("Account does not have enough balances: ", acnt.BalanceMap)
	} else if acnt.BalanceMap[utils.VOICE][0].Value != 40 {
		t.Error("Account does not have enough minutes in balance", acnt.BalanceMap[utils.VOICE][0].Value)
	}
}
開發者ID:cgrates,項目名稱:cgrates,代碼行數:11,代碼來源:ddazmbl3_test.go

示例4: TestExecuteActions3

func TestExecuteActions3(t *testing.T) {
	scheduler.NewScheduler().LoadActionTimings(acntDb3)
	time.Sleep(time.Millisecond) // Give time to scheduler to topup the account
	if acnt, err := acntDb3.GetAccount("*out:cgrates.org:12346"); err != nil {
		t.Error(err)
	} else if len(acnt.BalanceMap) != 1 {
		t.Error("Account does not have enough balances: ", acnt.BalanceMap)
	} else if acnt.BalanceMap[engine.MINUTES+engine.OUTBOUND][0].Value != 40 {
		t.Errorf("Account does not have enough minutes in balance", acnt.BalanceMap[engine.MINUTES+engine.OUTBOUND][0].Value)
	}
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:11,代碼來源:ddazmbl3_test.go

示例5: startScheduler

func startScheduler(internalSchedulerChan chan *scheduler.Scheduler, cacheDoneChan chan struct{}, ratingDB engine.RatingStorage, exitChan chan bool) {
	// Wait for cache to load data before starting
	cacheDone := <-cacheDoneChan
	cacheDoneChan <- cacheDone
	utils.Logger.Info("Starting CGRateS Scheduler.")
	sched := scheduler.NewScheduler(ratingDB)
	internalSchedulerChan <- sched

	sched.Loop()
	exitChan <- true // Should not get out of loop though
}
開發者ID:cgrates,項目名稱:cgrates,代碼行數:11,代碼來源:cgr-engine.go

示例6: TestExecuteActions

func TestExecuteActions(t *testing.T) {
	scheduler.NewScheduler().LoadActionPlans(ratingDb)
	time.Sleep(time.Millisecond) // Give time to scheduler to topup the account
	if acnt, err := acntDb.GetAccount("*out:cgrates.org:12344"); err != nil {
		t.Error(err)
	} else if len(acnt.BalanceMap) != 2 {
		t.Error("Account does not have enough balances: ", acnt.BalanceMap)
	} else if acnt.BalanceMap[utils.VOICE+engine.OUTBOUND][0].Value != 40 {
		t.Error("Account does not have enough minutes in balance", acnt.BalanceMap[utils.VOICE+engine.OUTBOUND][0].Value)
	} else if acnt.BalanceMap[utils.MONETARY+engine.OUTBOUND][0].Value != 10 {
		t.Error("Account does not have enough monetary balance", acnt.BalanceMap[utils.MONETARY+engine.OUTBOUND][0].Value)
	}
}
開發者ID:gale320,項目名稱:cgrates,代碼行數:13,代碼來源:ddazmbl1_test.go

示例7: main


//.........這裏部分代碼省略.........
		server.RpcRegister(cdrStats)
		server.RpcRegister(&apier.CDRStatsV1{cdrStats}) // Public APIs
	}

	responder := &engine.Responder{ExitChan: exitChan}
	apierRpc := &apier.ApierV1{StorDb: loadDb, RatingDb: ratingDb, AccountDb: accountDb, CdrDb: cdrDb, LogDb: logDb, Config: cfg, Responder: responder, CdrStatsSrv: cdrStats}

	if cfg.RaterEnabled && !cfg.BalancerEnabled && cfg.RaterBalancer != utils.INTERNAL {
		engine.Logger.Info("Registering Rater service")
		server.RpcRegister(responder)
		server.RpcRegister(apierRpc)
	}

	if cfg.BalancerEnabled {
		engine.Logger.Info("Registering Balancer service.")
		go stopBalancerSignalHandler()
		stopHandled = true
		responder.Bal = bal
		server.RpcRegister(responder)
		server.RpcRegister(apierRpc)
		if cfg.RaterEnabled {
			engine.Logger.Info("<Balancer> Registering internal rater")
			bal.AddClient("local", new(engine.ResponderWorker))
		}
	}

	if !stopHandled {
		go generalSignalHandler()
	}

	if cfg.SchedulerEnabled {
		engine.Logger.Info("Starting CGRateS Scheduler.")
		go func() {
			sched := scheduler.NewScheduler()
			go reloadSchedulerSingnalHandler(sched, accountDb)
			apierRpc.Sched = sched
			sched.LoadActionTimings(accountDb)
			sched.Loop()
		}()
	}

	var histServChan chan struct{} // Will be initialized only if the server starts
	if cfg.HistoryServerEnabled {
		histServChan = make(chan struct{})
		rpcWait = append(rpcWait, histServChan)
		go startHistoryServer(histServChan)
	}

	if cfg.HistoryAgentEnabled {
		engine.Logger.Info("Starting CGRateS History Agent.")
		go startHistoryAgent(histServChan)
	}

	var medChan chan struct{}
	if cfg.MediatorEnabled {
		engine.Logger.Info("Starting CGRateS Mediator service.")
		medChan = make(chan struct{})
		go startMediator(responder, logDb, cdrDb, cacheChan, medChan)
	}

	var cdrsChan chan struct{}
	if cfg.CDRSEnabled {
		engine.Logger.Info("Starting CGRateS CDRS service.")
		cdrsChan = make(chan struct{})
		httpWait = append(httpWait, cdrsChan)
		go startCDRS(responder, cdrDb, medChan, cdrsChan)
開發者ID:intralanman,項目名稱:cgrates,代碼行數:67,代碼來源:cgr-engine.go


注:本文中的github.com/cgrates/cgrates/scheduler.NewScheduler函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。