@@ -55,41 +55,53 @@ func (p *Plugin) GetResultChan() <-chan cpmtypes.Result {
55
55
func (p * Plugin ) Run () {
56
56
runTicker := time .NewTicker (* p .config .PluginGlobalConfig .InvokeInterval )
57
57
58
- for {
59
- select {
60
- case <- runTicker .C :
61
- glog .Info ("Start to run custom plugins" )
58
+ runner := func () {
59
+ glog .Info ("Start to run custom plugins" )
62
60
63
- for _ , rule := range p .config .Rules {
64
- p .syncChan <- struct {}{}
65
- p .Add (1 )
61
+ for _ , rule := range p .config .Rules {
62
+ p .syncChan <- struct {}{}
63
+ p .Add (1 )
66
64
67
- go func (rule * cpmtypes.CustomRule ) {
68
- defer p .Done ()
69
- defer func () {
70
- <- p .syncChan
71
- }()
65
+ go func (rule * cpmtypes.CustomRule ) {
66
+ defer p .Done ()
67
+ defer func () {
68
+ <- p .syncChan
69
+ }()
72
70
73
- start := time .Now ()
74
- exitStatus , message := p .run (* rule )
75
- end := time .Now ()
71
+ start := time .Now ()
72
+ exitStatus , message := p .run (* rule )
73
+ end := time .Now ()
76
74
77
- glog .V (3 ).Infof ("Rule: %+v. Start time: %v. End time: %v. Duration: %v" , rule , start , end , end .Sub (start ))
75
+ glog .V (3 ).Infof ("Rule: %+v. Start time: %v. End time: %v. Duration: %v" , rule , start , end , end .Sub (start ))
78
76
79
- result := cpmtypes.Result {
80
- Rule : rule ,
81
- ExitStatus : exitStatus ,
82
- Message : message ,
83
- }
77
+ result := cpmtypes.Result {
78
+ Rule : rule ,
79
+ ExitStatus : exitStatus ,
80
+ Message : message ,
81
+ }
82
+
83
+ p .resultChan <- result
84
+
85
+ glog .Infof ("Add check result %+v for rule %+v" , result , rule )
86
+ }(rule )
87
+ }
84
88
85
- p .resultChan <- result
89
+ p .Wait ()
90
+ glog .Info ("Finish running custom plugins" )
91
+ }
86
92
87
- glog .Infof ("Add check result %+v for rule %+v" , result , rule )
88
- }(rule )
89
- }
93
+ select {
94
+ case <- p .tomb .Stopping ():
95
+ glog .Info ("Stopping plugin execution" )
96
+ p .tomb .Done ()
97
+ default :
98
+ runner ()
99
+ }
90
100
91
- p .Wait ()
92
- glog .Info ("Finish running custom plugins" )
101
+ for {
102
+ select {
103
+ case <- runTicker .C :
104
+ runner ()
93
105
case <- p .tomb .Stopping ():
94
106
glog .Info ("Stopping plugin execution" )
95
107
p .tomb .Done ()
0 commit comments