dosubot[bot] commented on issue #8098:
URL: 
https://github.com/apache/incubator-devlake/issues/8098#issuecomment-2371337740

   <!-- Answer -->
   Yes, the tool can be modified to automatically stop the pipeline and clean 
the disk when the user clicks to stop the pipeline. The `CancelPipeline` 
function already handles stopping the pipeline. You can extend this function to 
include disk cleanup.
   
   Here is an example of how you might modify the `CancelPipeline` function to 
include disk cleanup:
   
   ```go
   func CancelPipeline(pipelineId uint64) errors.Error {
        // prevent RunPipelineInQueue from consuming pending pipelines
        pipeline := &models.Pipeline{}
        err := db.First(pipeline, dal.Where("id = ?", pipelineId))
        if err != nil {
                return errors.BadInput.New("pipeline not found")
        }
        if pipeline.Status == models.TASK_CREATED || pipeline.Status == 
models.TASK_RERUN {
                pipeline.Status = models.TASK_CANCELLED
                err = db.Update(pipeline)
                if err != nil {
                        return errors.Default.Wrap(err, "failed to update 
pipeline")
                }
                // now, with RunPipelineInQueue being block and target pipeline 
got updated
                // we should update the related tasks as well
                err = db.UpdateColumn(
                        &models.Task{},
                        "status", models.TASK_CANCELLED,
                        dal.Where("pipeline_id = ?", pipelineId),
                )
                if err != nil {
                        return errors.Default.Wrap(err, "failed to update 
pipeline tasks")
                }
                // the target pipeline is pending, no running, no need to 
perform the actual cancel operation
                return nil
        }
        pendingTasks, count, err := GetTasks(&TaskQuery{PipelineId: pipelineId, 
Pending: 1, Pagination: Pagination{PageSize: -1}})
        if err != nil {
                return errors.Convert(err)
        }
        if count == 0 {
                return nil
        }
        for _, pendingTask := range pendingTasks {
                _ = CancelTask(pendingTask.ID)
        }
   
        // Clean up disk
        logsPath, err := getPipelineLogsPath(pipeline)
        if err == nil {
                err = os.RemoveAll(logsPath)
                if err != nil {
                        return errors.Default.Wrap(err, "failed to clean up 
disk")
                }
        } else {
                return errors.Default.Wrap(err, "failed to get logs path for 
cleanup")
        }
   
        return errors.Convert(err)
   }
   ```
   
   Additionally, you can modify the UI to handle the cancel operation and 
trigger the disk cleanup. In the `PipelineInfo` component, the `handleCancel` 
function can be used to call the API that cancels the pipeline and performs the 
cleanup:
   
   ```tsx
   const handleCancel = async () => {
       const [success] = await operator(() => API.pipeline.remove(id), {
         setOperating,
       });
   
       if (success) {
         // setVersion((v) => v + 1);
       }
   };
   ```
   
   This modification ensures that when a pipeline is canceled, the associated 
disk space is also cleaned up 
<sup>[[1]](https://github.com/apache/incubator-devlake/blob/main/backend/server/services/pipeline.go)</sup><sup>[[2]](https://github.com/apache/incubator-devlake/blob/main/config-ui/src/routes/pipeline/components/info.tsx)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to