MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / Start

Method Start

db/event_manager.go:67–101  ·  view source on GitHub ↗

Starts the listener queue for the event manager

(ctx context.Context, maxProcesses uint, waitTime int)

Source from the content-addressed store, hash-verified

65
66// Starts the listener queue for the event manager
67func (em *EventManager) Start(ctx context.Context, maxProcesses uint, waitTime int) {
68
69 if maxProcesses == 0 {
70 maxProcesses = kMaxActiveEvents
71 }
72 if waitTime < 0 {
73 em.waitTime = kEventWaitTime
74 } else {
75 em.waitTime = waitTime
76 }
77
78 base.InfofCtx(ctx, base.KeyEvents, "Starting event manager with max processes:%d, wait time:%d ms", maxProcesses, em.waitTime)
79 // activeCountChannel limits the number of concurrent events being processed
80 em.activeCountChannel = make(chan bool, maxProcesses)
81
82 // asyncEventChannel stores the incoming events. It's set to 3x activeCountChannel, to
83 // handle temporary spikes in event inflow
84 em.asyncEventChannel = make(chan Event, 3*maxProcesses)
85
86 // Start the event channel worker go routine, which will work the event queue and spawn goroutines to process the
87 // event. Blocks if the activeCountChannel is full, to prevent spawning more than cap(activeCountChannel)
88 // goroutines.
89 go func() {
90 for {
91 select {
92 case <-em.terminator:
93 return
94 case event := <-em.asyncEventChannel:
95 em.activeCountChannel <- true
96 go em.ProcessEvent(ctx, event)
97 }
98 }
99 }()
100
101}
102
103// Concurrent processing of all async event handlers registered for the event type
104func (em *EventManager) ProcessEvent(ctx context.Context, event Event) {

Callers 10

TestDocumentChangeEventFunction · 0.95
TestDBStateChangeEventFunction · 0.95
TestCustomHandlerFunction · 0.95
TestUnhandledEventFunction · 0.95
TestWebhookBasicFunction · 0.95
TestWebhookOverflowsFunction · 0.95
TestWebhookOldDocFunction · 0.95
TestWebhookTimeoutFunction · 0.95
TestUnavailableWebhookFunction · 0.95

Calls 2

ProcessEventMethod · 0.95
InfofCtxFunction · 0.92

Tested by 10

TestDocumentChangeEventFunction · 0.76
TestDBStateChangeEventFunction · 0.76
TestCustomHandlerFunction · 0.76
TestUnhandledEventFunction · 0.76
TestWebhookBasicFunction · 0.76
TestWebhookOverflowsFunction · 0.76
TestWebhookOldDocFunction · 0.76
TestWebhookTimeoutFunction · 0.76
TestUnavailableWebhookFunction · 0.76