MCPcopy
hub / github.com/portainer/portainer / updateEndpointStatus

Function updateEndpointStatus

api/internal/snapshot/snapshot.go:269–304  ·  view source on GitHub ↗
(tx dataservices.DataStoreTx, endpoint *portainer.Endpoint, snapshotError error, pendingActionsService *pendingactions.PendingActionsService)

Source from the content-addressed store, hash-verified

267}
268
269func updateEndpointStatus(tx dataservices.DataStoreTx, endpoint *portainer.Endpoint, snapshotError error, pendingActionsService *pendingactions.PendingActionsService) {
270 latestEndpointReference, err := tx.Endpoint().Endpoint(endpoint.ID)
271 if latestEndpointReference == nil {
272 log.Debug().
273 Str("endpoint", endpoint.Name).
274 Str("URL", endpoint.URL).Err(err).
275 Msg("background schedule error (environment snapshot), environment not found inside the database anymore")
276
277 return
278 }
279
280 latestEndpointReference.Status = portainer.EndpointStatusUp
281
282 if snapshotError != nil {
283 log.Debug().
284 Str("endpoint", endpoint.Name).
285 Str("URL", endpoint.URL).Err(err).
286 Msg("background schedule error (environment snapshot), unable to create snapshot")
287
288 latestEndpointReference.Status = portainer.EndpointStatusDown
289 }
290
291 latestEndpointReference.Agent.Version = endpoint.Agent.Version
292
293 if err := tx.Endpoint().UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference); err != nil {
294 log.Debug().
295 Str("endpoint", endpoint.Name).
296 Str("URL", endpoint.URL).Err(err).
297 Msg("background schedule error (environment snapshot), unable to update environment")
298 }
299
300 // Run the pending actions
301 if latestEndpointReference.Status == portainer.EndpointStatusUp {
302 pendingActionsService.Execute(endpoint.ID)
303 }
304}
305
306// FetchDockerID fetches info.Swarm.Cluster.ID if environment(endpoint) is swarm and info.ID otherwise
307func FetchDockerID(snapshot portainer.DockerSnapshot) (string, error) {

Callers 1

snapshotEndpointsMethod · 0.70

Calls 3

EndpointMethod · 0.65
UpdateEndpointMethod · 0.65
ExecuteMethod · 0.65

Tested by

no test coverage detected