@@ -3,7 +3,10 @@ package cascade
33import (
44 "errors"
55 "net/http"
6+
7+ // pprof enabled in debug mode
68 _ "net/http/pprof"
9+
710 "reflect"
811 "sync"
912 "time"
@@ -187,12 +190,12 @@ func (c *Cascade) Register(vertex interface{}) error {
187190
188191 ok := t .Implements (reflect .TypeOf ((* Service )(nil )).Elem ())
189192 if ! ok {
190- return typeNotImplementError
193+ return errTypeNotImplementError
191194 }
192195
193196 /* Depender the type
194197 Information we know at this step is:
195- 1. VertexId
198+ 1. vertexID
196199 2. Vertex structure value (interface)
197200 And we fill vertex with this information
198201 */
@@ -203,7 +206,7 @@ func (c *Cascade) Register(vertex interface{}) error {
203206 order ++
204207 /* Add the types, which (if) current vertex provides
205208 Information we know at this step is:
206- 1. VertexId
209+ 1. vertexID
207210 2. Vertex structure value (interface)
208211 3. Provided type
209212 4. Provided type String name
@@ -254,7 +257,7 @@ func (c *Cascade) Init() error {
254257 return nil
255258}
256259
257- func (c * Cascade ) Serve () (error , <- chan * Result ) {
260+ func (c * Cascade ) Serve () (<- chan * Result , error ) {
258261 c .rwMutex .Lock ()
259262 defer c .rwMutex .Unlock ()
260263 c .startMainThread ()
@@ -264,8 +267,8 @@ func (c *Cascade) Serve() (error, <-chan *Result) {
264267 for nCopy != nil {
265268 err := c .configure (nCopy )
266269 if err != nil {
267- c .logger .Error ("backoff failed" , zap .String ("vertex id" , nCopy .Vertex .Id ), zap .Error (err ))
268- return err , nil
270+ c .logger .Error ("backoff failed" , zap .String ("vertex id" , nCopy .Vertex .ID ), zap .Error (err ))
271+ return nil , err
269272 }
270273
271274 nCopy = nCopy .Next
@@ -275,11 +278,11 @@ func (c *Cascade) Serve() (error, <-chan *Result) {
275278 for nCopy != nil {
276279 err := c .serve (nCopy )
277280 if err != nil {
278- return err , nil
281+ return nil , err
279282 }
280283 nCopy = nCopy .Next
281284 }
282- return nil , c .userResultsCh
285+ return c .userResultsCh , nil
283286}
284287
285288func (c * Cascade ) Stop () error {
@@ -319,18 +322,18 @@ func (c *Cascade) startMainThread() {
319322 return
320323 }
321324
322- c .logger .Debug ("processing error in the main thread" , zap .String ("vertex id" , res .vertexId ))
325+ c .logger .Debug ("processing error in the main thread" , zap .String ("vertex id" , res .vertexID ))
323326 if c .checkLeafErrorTime (res ) {
324- c .logger .Debug ("error processing skipped because vertex already restartedTime by the root" , zap .String ("vertex id" , res .vertexId ))
327+ c .logger .Debug ("error processing skipped because vertex already restartedTime by the root" , zap .String ("vertex id" , res .vertexID ))
325328 c .sendResultToUser (res )
326329 c .rwMutex .Unlock ()
327330 continue
328331 }
329332
330333 // get vertex from the graph
331- vertex := c .graph .GetVertex (res .vertexId )
334+ vertex := c .graph .GetVertex (res .vertexID )
332335 if vertex == nil {
333- c .logger .Error ("failed to get vertex from the graph, vertex is nil" , zap .String ("vertex id from the handleErrorCh channel" , res .vertexId ))
336+ c .logger .Error ("failed to get vertex from the graph, vertex is nil" , zap .String ("vertex id from the handleErrorCh channel" , res .vertexID ))
334337 c .userResultsCh <- & Result {
335338 Error : FailedToGetTheVertex ,
336339 VertexID : "" ,
@@ -341,12 +344,12 @@ func (c *Cascade) startMainThread() {
341344
342345 // reset vertex and dependencies to the initial state
343346 // NumOfDeps and Visited/Visiting
344- vertices := c .resetVertices (vertex )
347+ vertices := c .graph . Reset (vertex )
345348
346349 // Topologically sort the graph
347350 sorted := structures .TopologicalSort (vertices )
348351 if sorted == nil {
349- c .logger .Error ("sorted list should not be nil" , zap .String ("vertex id from the handleErrorCh channel" , res .vertexId ))
352+ c .logger .Error ("sorted list should not be nil" , zap .String ("vertex id from the handleErrorCh channel" , res .vertexID ))
350353 c .userResultsCh <- & Result {
351354 Error : FailedToSortTheGraph ,
352355 VertexID : "" ,
@@ -377,10 +380,10 @@ func (c *Cascade) startMainThread() {
377380 for headCopy != nil {
378381 berr := backoff .Retry (c .backoffInit (headCopy .Vertex ), b )
379382 if berr != nil {
380- c .logger .Error ("backoff failed" , zap .String ("vertex id" , headCopy .Vertex .Id ), zap .Error (berr ))
383+ c .logger .Error ("backoff failed" , zap .String ("vertex id" , headCopy .Vertex .ID ), zap .Error (berr ))
381384 c .userResultsCh <- & Result {
382385 Error : ErrorDuringInit ,
383- VertexID : headCopy .Vertex .Id ,
386+ VertexID : headCopy .Vertex .ID ,
384387 }
385388 c .rwMutex .Unlock ()
386389 return
@@ -396,9 +399,9 @@ func (c *Cascade) startMainThread() {
396399 if berr != nil {
397400 c .userResultsCh <- & Result {
398401 Error : ErrorDuringInit ,
399- VertexID : headCopy .Vertex .Id ,
402+ VertexID : headCopy .Vertex .ID ,
400403 }
401- c .logger .Error ("backoff failed" , zap .String ("vertex id" , headCopy .Vertex .Id ), zap .Error (berr ))
404+ c .logger .Error ("backoff failed" , zap .String ("vertex id" , headCopy .Vertex .ID ), zap .Error (berr ))
402405 c .rwMutex .Unlock ()
403406 return
404407 }
@@ -413,9 +416,9 @@ func (c *Cascade) startMainThread() {
413416 if err != nil {
414417 c .userResultsCh <- & Result {
415418 Error : ErrorDuringServe ,
416- VertexID : headCopy .Vertex .Id ,
419+ VertexID : headCopy .Vertex .ID ,
417420 }
418- c .logger .Error ("fatal error during the serve in the main thread" , zap .String ("vertex id" , headCopy .Vertex .Id ), zap .Error (err ))
421+ c .logger .Error ("fatal error during the serve in the main thread" , zap .String ("vertex id" , headCopy .Vertex .ID ), zap .Error (err ))
419422 c .rwMutex .Unlock ()
420423 return
421424 }
0 commit comments