@@ -60,45 +60,49 @@ func NewGitWatcher(
60
60
}
61
61
}
62
62
63
- // Start runs the watcher loop and blocks until a fatal error occurs
64
- func (w * GitWatcher ) Start () error {
65
- zap .L ().Debug ("git watcher initialising, waiting for first state to be set" )
66
-
67
- // wait for the first config event to set the initial state
63
+ func (w * GitWatcher ) __waitpoint__start_wait_init () {
68
64
<- w .initialise
65
+ }
69
66
70
- zap .L ().Debug ("git watcher initialised" , zap .Any ("initial_state" , w .state ))
71
-
72
- f := func () (err error ) {
73
- select {
74
- case newState := <- w .newState :
75
- zap .L ().Debug ("git watcher received new state" ,
76
- zap .Any ("new_state" , newState ))
77
-
78
- return w .doReconfigure (newState )
67
+ func (w * GitWatcher ) __waitpoint__start_select_states () (err error ) {
68
+ select {
69
+ case newState := <- w .newState :
70
+ zap .L ().Debug ("git watcher received new state" ,
71
+ zap .Any ("new_state" , newState ))
79
72
80
- case <- w .stateReq :
81
- w .stateRes <- w .state
73
+ return w .doReconfigure (newState )
82
74
83
- case event := <- w .targetsWatcher .Events :
84
- zap .L ().Debug ("git watcher received a target event" ,
85
- zap .Any ("new_state" , event ))
75
+ case <- w .stateReq :
76
+ w .stateRes <- w .state
86
77
87
- if e := w .handle (event ); e != nil {
88
- zap .L ().Error ("failed to handle event" ,
89
- zap .String ("url" , event .URL ),
90
- zap .Error (e ))
91
- }
78
+ case event := <- w .targetsWatcher .Events :
79
+ zap .L ().Debug ("git watcher received a target event" ,
80
+ zap .Any ("new_state" , event ))
92
81
93
- case e := <- errorMultiplex (w .errors , w .targetsWatcher .Errors ):
94
- zap .L ().Error ("git error" ,
82
+ if e := w .handle (event ); e != nil {
83
+ zap .L ().Error ("failed to handle event" ,
84
+ zap .String ("url" , event .URL ),
95
85
zap .Error (e ))
96
86
}
97
- return
87
+
88
+ case e := <- errorMultiplex (w .errors , w .targetsWatcher .Errors ):
89
+ zap .L ().Error ("git error" ,
90
+ zap .Error (e ))
98
91
}
92
+ return
93
+ }
94
+
95
+ // Start runs the watcher loop and blocks until a fatal error occurs
96
+ func (w * GitWatcher ) Start () error {
97
+ zap .L ().Debug ("git watcher initialising, waiting for first state to be set" )
98
+
99
+ // wait for the first config event to set the initial state
100
+ w .__waitpoint__start_wait_init ()
101
+
102
+ zap .L ().Debug ("git watcher initialised" , zap .Any ("initial_state" , w .state ))
99
103
100
104
for {
101
- err := f ()
105
+ err := w . __waitpoint__start_select_states ()
102
106
if err != nil {
103
107
return err
104
108
}
@@ -203,13 +207,18 @@ func (w *GitWatcher) watchTargets() (err error) {
203
207
}()
204
208
zap .L ().Debug ("created targets watcher, awaiting setup" )
205
209
210
+ err = w .__waitpoint__watch_targets (errs )
211
+
212
+ zap .L ().Debug ("targets watcher initialised" )
213
+
214
+ return
215
+ }
216
+
217
+ func (w * GitWatcher ) __waitpoint__watch_targets (errs chan error ) (err error ) {
206
218
select {
207
219
case <- w .targetsWatcher .InitialDone :
208
220
case err = <- errs :
209
221
}
210
-
211
- zap .L ().Debug ("targets watcher initialised" )
212
-
213
222
return
214
223
}
215
224
@@ -222,7 +231,7 @@ func (w *GitWatcher) handle(e gitwatch.Event) (err error) {
222
231
zap .String ("target" , target .Name ),
223
232
zap .String ("url" , target .RepoURL ),
224
233
zap .Time ("timestamp" , e .Timestamp ))
225
- w .send (target , e .Path , false )
234
+ w .__waitpoint__send_target_task (target , e .Path , false )
226
235
return nil
227
236
}
228
237
@@ -257,7 +266,7 @@ func (w GitWatcher) executeTargets(targets []task.Target, shutdown bool) {
257
266
zap .Int ("targets" , len (targets )))
258
267
259
268
for _ , t := range targets {
260
- w .send (t , filepath .Join (w .directory , t .Name ), shutdown )
269
+ w .__waitpoint__send_target_task (t , filepath .Join (w .directory , t .Name ), shutdown )
261
270
}
262
271
}
263
272
@@ -270,7 +279,7 @@ func (w GitWatcher) getTarget(url string) (target task.Target, exists bool) {
270
279
return
271
280
}
272
281
273
- func (w GitWatcher ) send (target task.Target , path string , shutdown bool ) {
282
+ func (w GitWatcher ) __waitpoint__send_target_task (target task.Target , path string , shutdown bool ) {
274
283
w .bus <- task.ExecutionTask {
275
284
Target : target ,
276
285
Path : path ,
0 commit comments