@@ -140,12 +140,10 @@ func (w *Watcher) Process(ctx context.Context, msg *bus.Message) {
140140 switch msg .Topic {
141141 case bus .ConfigApplyRequestTopic :
142142 w .handleConfigApplyRequest (ctx , msg )
143- case bus .ConfigApplySuccessfulTopic :
144- w .handleConfigApplySuccess (ctx , msg )
145- case bus .ConfigApplyCompleteTopic :
146- w .handleConfigApplyComplete (ctx , msg )
147143 case bus .DataPlaneHealthRequestTopic :
148144 w .handleHealthRequest (ctx )
145+ case bus .EnableWatchersTopic :
146+ w .handleEnableWatchers (ctx , msg )
149147 default :
150148 slog .DebugContext (ctx , "Watcher plugin unknown topic" , "topic" , msg .Topic )
151149 }
@@ -154,12 +152,43 @@ func (w *Watcher) Process(ctx context.Context, msg *bus.Message) {
154152func (* Watcher ) Subscriptions () []string {
155153 return []string {
156154 bus .ConfigApplyRequestTopic ,
157- bus .ConfigApplySuccessfulTopic ,
158- bus .ConfigApplyCompleteTopic ,
159155 bus .DataPlaneHealthRequestTopic ,
156+ bus .EnableWatchersTopic ,
160157 }
161158}
162159
160+ func (w * Watcher ) handleEnableWatchers (ctx context.Context , msg * bus.Message ) {
161+ slog .DebugContext (ctx , "Watcher plugin received enable watchers message" )
162+ enableWatchersMessage , ok := msg .Data .(* model.EnableWatchers )
163+ if ! ok {
164+ slog .ErrorContext (ctx , "Unable to cast message payload to *model.EnableWatchers" , "payload" ,
165+ msg .Data , "topic" , msg .Topic )
166+
167+ return
168+ }
169+
170+ instanceID := enableWatchersMessage .InstanceID
171+ configContext := enableWatchersMessage .ConfigContext
172+
173+ // if config apply ended in a reload there is no need to reparse the config so an empty config context is sent
174+ // from the file plugin
175+ if configContext .InstanceID != "" {
176+ w .instanceWatcherService .HandleNginxConfigContextUpdate (ctx , instanceID , configContext )
177+ }
178+
179+ w .watcherMutex .Lock ()
180+ w .instancesWithConfigApplyInProgress = slices .DeleteFunc (
181+ w .instancesWithConfigApplyInProgress ,
182+ func (element string ) bool {
183+ return element == instanceID
184+ },
185+ )
186+
187+ w .fileWatcherService .SetEnabled (true )
188+ w .instanceWatcherService .SetEnabled (true )
189+ w .watcherMutex .Unlock ()
190+ }
191+
163192func (w * Watcher ) handleConfigApplyRequest (ctx context.Context , msg * bus.Message ) {
164193 slog .DebugContext (ctx , "Watcher plugin received config apply request message" )
165194 managementPlaneRequest , ok := msg .Data .(* mpi.ManagementPlaneRequest )
@@ -188,69 +217,13 @@ func (w *Watcher) handleConfigApplyRequest(ctx context.Context, msg *bus.Message
188217 w .instanceWatcherService .SetEnabled (false )
189218}
190219
191- func (w * Watcher ) handleConfigApplySuccess (ctx context.Context , msg * bus.Message ) {
192- slog .DebugContext (ctx , "Watcher plugin received config apply success message" )
193- successMessage , ok := msg .Data .(* model.ConfigApplySuccess )
194- if ! ok {
195- slog .ErrorContext (ctx , "Unable to cast message payload to *model.ConfigApplySuccess" , "payload" ,
196- msg .Data , "topic" , msg .Topic )
197-
198- return
199- }
200-
201- instanceID := successMessage .DataPlaneResponse .GetInstanceId ()
202-
203- // If the config apply had no changes to any files, it is results in a ConfigApplySuccessfulTopic with an empty
204- // configContext being sent, there is no need to reparse the config as no change has occurred.
205- if successMessage .ConfigContext .InstanceID != "" {
206- w .instanceWatcherService .HandleNginxConfigContextUpdate (ctx , instanceID , successMessage .ConfigContext )
207- }
208-
209- w .watcherMutex .Lock ()
210- w .instancesWithConfigApplyInProgress = slices .DeleteFunc (
211- w .instancesWithConfigApplyInProgress ,
212- func (element string ) bool {
213- return element == instanceID
214- },
215- )
216-
217- w .fileWatcherService .SetEnabled (true )
218- w .instanceWatcherService .SetEnabled (true )
219- w .watcherMutex .Unlock ()
220- }
221-
222220func (w * Watcher ) handleHealthRequest (ctx context.Context ) {
223221 slog .DebugContext (ctx , "Watcher plugin received health request message" )
224222 w .messagePipe .Process (ctx , & bus.Message {
225223 Topic : bus .DataPlaneHealthResponseTopic , Data : w .healthWatcherService .InstancesHealth (),
226224 })
227225}
228226
229- func (w * Watcher ) handleConfigApplyComplete (ctx context.Context , msg * bus.Message ) {
230- slog .DebugContext (ctx , "Watcher plugin received config apply complete message" )
231- response , ok := msg .Data .(* mpi.DataPlaneResponse )
232- if ! ok {
233- slog .ErrorContext (ctx , "Unable to cast message payload to *mpi.DataPlaneResponse" , "payload" ,
234- msg .Data , "topic" , msg .Topic )
235-
236- return
237- }
238-
239- instanceID := response .GetInstanceId ()
240-
241- w .watcherMutex .Lock ()
242- defer w .watcherMutex .Unlock ()
243- w .instancesWithConfigApplyInProgress = slices .DeleteFunc (
244- w .instancesWithConfigApplyInProgress ,
245- func (element string ) bool {
246- return element == instanceID
247- },
248- )
249-
250- w .instanceWatcherService .SetEnabled (true )
251- w .fileWatcherService .SetEnabled (true )
252- }
253-
254227func (w * Watcher ) monitorWatchers (ctx context.Context ) {
255228 for {
256229 select {
0 commit comments