@@ -10,7 +10,7 @@ import (
1010
1111 "github.com/spiral/endure/pkg/fsm"
1212 "github.com/spiral/endure/pkg/graph"
13- "github.com/spiral/endure/pkg/linked_list"
13+ ll "github.com/spiral/endure/pkg/linked_list"
1414 "github.com/spiral/errors"
1515 "go.uber.org/zap"
1616 "go.uber.org/zap/zapcore"
@@ -55,7 +55,7 @@ type Endure struct {
5555 // Dependency graph
5656 graph * graph.Graph
5757 // DLL used as run list to run in order
58- runList * linked_list .DoublyLinkedList
58+ runList * ll .DoublyLinkedList
5959 // logger
6060 logger * zap.Logger
6161 // OPTIONS
@@ -65,8 +65,11 @@ type Endure struct {
6565 initialInterval time.Duration
6666 stopTimeout time.Duration
6767
68- deps map [string ]interface {}
69- disabled map [string ]bool
68+ // deps is a map with all saved deps
69+ deps map [string ]interface {}
70+ // disabled is a map with disabled deps
71+ disabled map [string ]bool
72+ // initialized vertices map
7073 initialized map [string ]bool
7174
7275 // Graph visualizer
@@ -138,7 +141,7 @@ func NewContainer(logger *zap.Logger, options ...Options) (*Endure, error) {
138141 c .FSM = fsm .NewFSM (fsm .Uninitialized , transitionMap )
139142
140143 c .graph = graph .NewGraph ()
141- c .runList = linked_list .NewDoublyLinkedList ()
144+ c .runList = ll .NewDoublyLinkedList ()
142145
143146 // Main thread channels
144147 c .handleErrorCh = make (chan * result )
@@ -272,10 +275,6 @@ func (e *Endure) reRegister(vertex interface{}) error {
272275 t := reflect .TypeOf (vertex )
273276 vertexID := removePointerAsterisk (t .String ())
274277
275- if t .Kind () != reflect .Ptr {
276- return errors .E (op , errors .Register , errors .Errorf ("you should pass pointer to the structure instead of value" ))
277- }
278-
279278 err := e .register (vertexID , vertex )
280279 if err != nil {
281280 return errors .E (op , errors .Register , err )
@@ -370,7 +369,7 @@ START:
370369 return errors .E (op , errors .Init , errors .Errorf ("graph should contain at least 1 vertex, possibly you forget to invoke registers" ))
371370 }
372371
373- e .runList = linked_list .NewDoublyLinkedList ()
372+ e .runList = ll .NewDoublyLinkedList ()
374373 for i := len (sorted ) - 1 ; i >= 0 ; i -- {
375374 e .runList .Push (sorted [i ])
376375 }
@@ -382,6 +381,7 @@ START:
382381 head = head .Next
383382 continue
384383 }
384+
385385 // check for disabled, because that can be interface
386386 if _ , ok := e .disabled [head .Vertex .ID ]; ok {
387387 err = e .removeVertex (head )
@@ -431,10 +431,6 @@ func (e *Endure) Start() (<-chan *Result, error) {
431431
432432 nCopy := e .runList .Head
433433 for nCopy != nil {
434- if nCopy .Vertex .IsDisabled {
435- nCopy = nCopy .Next
436- continue
437- }
438434 atLeastOne = true
439435 nCopy .Vertex .SetState (fsm .Starting )
440436 err := e .serveInternal (nCopy )
@@ -448,7 +444,7 @@ func (e *Endure) Start() (<-chan *Result, error) {
448444 }
449445 // all vertices disabled
450446 if ! atLeastOne {
451- return nil , errors .E (op , errors .Disabled , errors .Str ("all vertices disabled, nothing to serveInternal " ))
447+ return nil , errors .E (op , errors .Disabled , errors .Str ("all vertices disabled, nothing to run " ))
452448 }
453449 return e .userResultsCh , nil
454450}
@@ -457,20 +453,27 @@ func (e *Endure) Start() (<-chan *Result, error) {
457453// Do not change this method fn, sync with constants in the beginning of this file
458454func (e * Endure ) Shutdown () error {
459455 e .logger .Info ("exiting from the Endure" )
456+ if e .runList == nil {
457+ return nil
458+ }
460459 return e .shutdown (e .runList .Head , true )
461460}
462461
463- func (e * Endure ) removeVertex (head * linked_list .DllNode ) error {
462+ func (e * Endure ) removeVertex (head * ll .DllNode ) error {
464463 const op = errors .Op ("endure_disable" )
465464 e .logger .Debug ("found disabled vertex" , zap .String ("id" , head .Vertex .ID ))
466465 // add vertex to the map with disabled vertices
467466 for providesID := range head .Vertex .Provides {
467+ // disable all types which vertex provides as a root
468468 e .disabled [providesID ] = true
469469 delete (e .deps , providesID )
470470 }
471+
471472 e .disabled [head .Vertex .ID ] = true
473+
472474 // reset run list
473- e .runList .Reset ()
475+ e .runList = nil
476+
474477 // reset graph
475478 e .graph = nil
476479 e .graph = graph .NewGraph ()
@@ -485,8 +488,5 @@ func (e *Endure) removeVertex(head *linked_list.DllNode) error {
485488 }
486489 }
487490
488- e .runList .Remove (head )
489- head .Vertex = nil
490-
491491 return nil
492492}
0 commit comments