@ -45,39 +45,41 @@ func (runner *SnapshotJobRunner) GetSchedule() *portainer.Schedule {
// As a snapshot can be a long process, to avoid any concurrency issue we
// retrieve the latest version of the endpoint right after a snapshot.
func ( runner * SnapshotJobRunner ) Run ( ) {
endpoints , err := runner . context . endpointService . Endpoints ( )
if err != nil {
log . Printf ( "background schedule error (endpoint snapshot). Unable to retrieve endpoint list (err=%s)\n" , err )
return
}
for _ , endpoint := range endpoints {
if endpoint . Type == portainer . AzureEnvironment {
continue
go func ( ) {
endpoints , err := runner . context . endpointService . Endpoints ( )
if err != nil {
log . Printf ( "background schedule error (endpoint snapshot). Unable to retrieve endpoint list (err=%s)\n" , err )
return
}
snapshot , snapshotError := runner . context . snapshotter . CreateSnapshot ( & endpoint )
for _ , endpoint := range endpoints {
if endpoint . Type == portainer . AzureEnvironment {
continue
}
latestEndpointReference , err := runner . context . endpointService . Endpoint ( endpoint . ID )
if latestEndpointReference == nil {
log . Printf ( "background schedule error (endpoint snapshot). Endpoint not found inside the database anymore (endpoint=%s, URL=%s) (err=%s)\n" , endpoint . Name , endpoint . URL , err )
continue
}
snapshot , snapshotError := runner . context . snapshotter . CreateSnapshot ( & endpoint )
latestEndpointReference . Status = portainer . EndpointStatusUp
if snapshotError ! = nil {
log . Printf ( "background schedule error (endpoint snapshot). Unable to create snapshot (endpoint=%s, URL=%s) (err=%s)\n", endpoint . Name , endpoint . URL , snapshotErro r)
latestEndpointReference . Status = portainer . EndpointStatusDown
}
latestEndpointReference , err := runner . context . endpointService . Endpoint ( endpoint . ID )
if latestEndpointReference == nil {
log . Printf ( "background schedule error (endpoint snapshot). Endpoint not found inside the database anymore (endpoint=%s, URL=%s) (err=%s)\n" , endpoint . Name , endpoint . URL , err )
continue
}
if snapshot != nil {
latestEndpointReference . Snapshots = [ ] portainer . Snapshot { * snapshot }
}
latestEndpointReference . Status = portainer . EndpointStatusUp
if snapshotError != nil {
log . Printf ( "background schedule error (endpoint snapshot). Unable to create snapshot (endpoint=%s, URL=%s) (err=%s)\n" , endpoint . Name , endpoint . URL , snapshotError )
latestEndpointReference . Status = portainer . EndpointStatusDown
}
err = runner . context . endpointService . UpdateEndpoint ( latestEndpointReference . ID , latestEndpointReference )
if err != nil {
log . Printf ( "background schedule error (endpoint snapshot). Unable to update endpoint (endpoint=%s, URL=%s) (err=%s)\n" , endpoint . Name , endpoint . URL , err )
return
if snapshot != nil {
latestEndpointReference . Snapshots = [ ] portainer . Snapshot { * snapshot }
}
err = runner . context . endpointService . UpdateEndpoint ( latestEndpointReference . ID , latestEndpointReference )
if err != nil {
log . Printf ( "background schedule error (endpoint snapshot). Unable to update endpoint (endpoint=%s, URL=%s) (err=%s)\n" , endpoint . Name , endpoint . URL , err )
return
}
}
}
} ( )
}