diff --git a/api/http/handler/edgejobs/edgejob_tasklogs_clear.go b/api/http/handler/edgejobs/edgejob_tasklogs_clear.go index 7d339b9e8..6fa1d18e9 100644 --- a/api/http/handler/edgejobs/edgejob_tasklogs_clear.go +++ b/api/http/handler/edgejobs/edgejob_tasklogs_clear.go @@ -44,22 +44,33 @@ func (handler *Handler) edgeJobTasksClear(w http.ResponseWriter, r *http.Request return httperror.InternalServerError("Unable to find an Edge job with the specified identifier inside the database", err) } + err = handler.FileService.ClearEdgeJobTaskLogs(strconv.Itoa(edgeJobID), strconv.Itoa(taskID)) + if err != nil { + return httperror.InternalServerError("Unable to clear log file from disk", err) + } + endpointID := portainer.EndpointID(taskID) endpointsFromGroups, err := edge.GetEndpointsFromEdgeGroups(edgeJob.EdgeGroups, handler.DataStore) if err != nil { return httperror.InternalServerError("Unable to get Endpoints from EdgeGroups", err) } - if slices.Contains(endpointsFromGroups, endpointID) { - edgeJob.GroupLogsCollection[endpointID] = portainer.EdgeJobEndpointMeta{ - CollectLogs: false, - LogsStatus: portainer.EdgeJobLogsStatusIdle, + err = handler.DataStore.EdgeJob().UpdateEdgeJobFunc(edgeJob.ID, func(j *portainer.EdgeJob) { + if slices.Contains(endpointsFromGroups, endpointID) { + j.GroupLogsCollection[endpointID] = portainer.EdgeJobEndpointMeta{ + CollectLogs: false, + LogsStatus: portainer.EdgeJobLogsStatusIdle, + } + } else { + meta := j.Endpoints[endpointID] + meta.CollectLogs = false + meta.LogsStatus = portainer.EdgeJobLogsStatusIdle + j.Endpoints[endpointID] = meta } - } else { - meta := edgeJob.Endpoints[endpointID] - meta.CollectLogs = false - meta.LogsStatus = portainer.EdgeJobLogsStatusIdle - edgeJob.Endpoints[endpointID] = meta + }) + + if err != nil { + return httperror.InternalServerError("Unable to persist Edge job changes in the database", err) } err = handler.FileService.ClearEdgeJobTaskLogs(strconv.Itoa(edgeJobID), strconv.Itoa(taskID)) @@ -74,10 +85,5 @@ func (handler *Handler) edgeJobTasksClear(w http.ResponseWriter, r *http.Request handler.ReverseTunnelService.AddEdgeJob(endpoint, edgeJob) - err = handler.DataStore.EdgeJob().UpdateEdgeJob(edgeJob.ID, edgeJob) - if err != nil { - return httperror.InternalServerError("Unable to persist Edge job changes in the database", err) - } - return response.Empty(w) }