MCPcopy
hub / github.com/aceld/zinx / StartOneWorker

Method StartOneWorker

znet/msghandler.go:412–444  ·  view source on GitHub ↗

StartOneWorker starts a worker workflow (启动一个Worker工作流程)

(workerID int, taskQueue chan ziface.IRequest)

Source from the content-addressed store, hash-verified

410// StartOneWorker starts a worker workflow
411// (启动一个Worker工作流程)
412func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan ziface.IRequest) {
413 zlog.Ins().DebugF("Worker ID = %d is started.", workerID)
414 // Continuously wait for messages in the queue
415 // (不断地等待队列中的消息)
416 for {
417 select {
418 // If there is a message, take out the Request from the queue and execute the bound business method
419 // (有消息则取出队列的Request,并执行绑定的业务方法)
420 case request, ok := <-taskQueue:
421 if !ok {
422 // DynamicBind Mode, destroy current worker by close the taskQueue
423 // (DynamicBind模式下,临时创建的worker, 是通过关闭taskQueue 来销毁当前worker)
424 zlog.Ins().ErrorF(" taskQueue is closed, Worker ID = %d quit", workerID)
425 return
426 }
427 switch req := request.(type) {
428
429 case ziface.IFuncRequest:
430 // Internal function call request (内部函数调用request)
431
432 mh.doFuncHandler(req, workerID)
433
434 case ziface.IRequest: // Client message request
435
436 if !zconf.GlobalObject.RouterSlicesMode {
437 mh.doMsgHandler(req, workerID)
438 } else if zconf.GlobalObject.RouterSlicesMode {
439 mh.doMsgHandlerSlices(req, workerID)
440 }
441 }
442 }
443 }
444}
445
446// StartWorkerPool starts the worker pool
447func (mh *MsgHandle) StartWorkerPool() {

Callers 2

StartWorkerPoolMethod · 0.95
useWorkerFunction · 0.80

Calls 6

doFuncHandlerMethod · 0.95
doMsgHandlerMethod · 0.95
doMsgHandlerSlicesMethod · 0.95
InsFunction · 0.92
DebugFMethod · 0.65
ErrorFMethod · 0.65

Tested by

no test coverage detected