|
|
|
@@ -2,19 +2,13 @@ package cloudbrain |
|
|
|
|
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
) |
|
|
|
|
|
|
|
func GenerateTask(ctx *context.Context, image, command string) error { |
|
|
|
nowStr := strconv.FormatInt(time.Now().Unix(), 10) |
|
|
|
|
|
|
|
jobName := fmt.Sprintf("%s%s", ctx.User.Name, nowStr[len(nowStr)-5:]) |
|
|
|
func GenerateTask(ctx *context.Context, jobName, image, command string) error { |
|
|
|
jobResult, err := CreateJob(jobName, models.CreateJobParams{ |
|
|
|
JobName: jobName, |
|
|
|
RetryCount: 1, |
|
|
|
@@ -22,7 +16,7 @@ func GenerateTask(ctx *context.Context, image, command string) error { |
|
|
|
Image: image, |
|
|
|
TaskRoles: []models.TaskRole{ |
|
|
|
{ |
|
|
|
Name: jobName, |
|
|
|
Name: "task1", |
|
|
|
TaskNumber: 1, |
|
|
|
MinSucceededTaskCount: 1, |
|
|
|
MinFailedTaskCount: 1, |
|
|
|
@@ -45,10 +39,11 @@ func GenerateTask(ctx *context.Context, image, command string) error { |
|
|
|
|
|
|
|
var jobID = jobResult.Payload["jobId"].(string) |
|
|
|
err = models.CreateCloudbrain(&models.Cloudbrain{ |
|
|
|
Status: int32(models.JobWaiting), |
|
|
|
UserID: ctx.User.ID, |
|
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
|
JobID: jobID, |
|
|
|
Status: int32(models.JobWaiting), |
|
|
|
UserID: ctx.User.ID, |
|
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
|
JobID: jobID, |
|
|
|
JobName: jobName, |
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|