Browse Source

del job

tags/v1.21.12.2^2
lewis 4 years ago
parent
commit
a3a78ee885
4 changed files with 59 additions and 0 deletions
  1. +4
    -0
      modules/storage/local.go
  2. +25
    -0
      modules/storage/minio.go
  3. +1
    -0
      modules/storage/storage.go
  4. +29
    -0
      routers/repo/cloudbrain.go

+ 4
- 0
modules/storage/local.go View File

@@ -80,3 +80,7 @@ func (l *LocalStorage) HasObject(path string) (bool, error) {
func (l *LocalStorage) UploadObject(fileName, filePath string) error {
return nil
}

func (l *LocalStorage) DeleteDir(dir string) error {
return nil
}

+ 25
- 0
modules/storage/minio.go View File

@@ -11,6 +11,8 @@ import (
"strings"
"time"

"code.gitea.io/gitea/modules/log"

"github.com/minio/minio-go"
)

@@ -76,6 +78,29 @@ func (m *MinioStorage) Delete(path string) error {
return m.client.RemoveObject(m.bucket, m.buildMinioPath(path))
}

// Delete delete a file
func (m *MinioStorage) DeleteDir(dir string) error {
objectsCh := make(chan string)

// Send object names that are needed to be removed to objectsCh
go func() {
defer close(objectsCh)
// List all objects from a bucket-name with a matching prefix.
for object := range m.client.ListObjects(m.bucket, dir, true, nil) {
if object.Err != nil {
log.Error("ListObjects failed:%v", object.Err)
}
objectsCh <- object.Key
}
}()

for rErr := range m.client.RemoveObjects(m.bucket, objectsCh) {
log.Error("Error detected during deletion: ", rErr)
}

return nil
}

//Get Presigned URL for get object
func (m *MinioStorage) PresignedGetURL(path string, fileName string) (string, error) {
// Set request parameters for content-disposition.


+ 1
- 0
modules/storage/storage.go View File

@@ -23,6 +23,7 @@ type ObjectStorage interface {
Save(path string, r io.Reader) (int64, error)
Open(path string) (io.ReadCloser, error)
Delete(path string) error
DeleteDir(dir string) error
PresignedGetURL(path string, fileName string) (string, error)
PresignedPutURL(path string) (string, error)
HasObject(path string) (bool, error)


+ 29
- 0
routers/repo/cloudbrain.go View File

@@ -478,6 +478,9 @@ func CloudBrainDel(ctx *context.Context) {
ctx.ServerError("DeleteJob failed", err)
return
}

//todo: delete local and oss's job
deleteJobName(task.JobName, models.TypeCloudBrainOne)
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob")
}

@@ -756,6 +759,32 @@ func mkModelPath(modelPath string) error {
return nil
}

func deleteJobName(jobName string, cloudbrainType int) error {
//delete local
localJobPath := setting.JobPath + jobName
log.Info("%s", localJobPath)
err := os.RemoveAll(localJobPath)
if err != nil {
log.Error("RemoveAll(%s) failed:%v", localJobPath, err)
}

//delete oss
if cloudbrainType == models.TypeCloudBrainOne {
dirPath := setting.CBCodePathPrefix + jobName + "/"
log.Info("%s", dirPath)
err = storage.Attachments.DeleteDir(dirPath)
if err != nil {
log.Error("Delete(%s) failed:%v", localJobPath, err)
}
} else if cloudbrainType == models.TypeCloudBrainTwo {

} else {
log.Error("cloudbrainType(%d) error", cloudbrainType)
}

return nil
}

func SyncCloudbrainStatus() {
cloudBrains, err := models.GetCloudBrainUnStoppedJob()
if err != nil {


Loading…
Cancel
Save