Skip to content

Commit

Permalink
部署任务
Browse files Browse the repository at this point in the history
  • Loading branch information
donknap committed Nov 30, 2023
1 parent 3712a0d commit 38a27d6
Show file tree
Hide file tree
Showing 14 changed files with 862 additions and 69 deletions.
133 changes: 133 additions & 0 deletions app/application/http/controller/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package controller

import (
"errors"
"github.com/donknap/dpanel/app/application/logic"
"github.com/donknap/dpanel/common/dao"
"github.com/gin-gonic/gin"
"github.com/we7coreteam/w7-rangine-go/src/http/controller"
)

type Log struct {
controller.Abstract
}

func (self Log) Task(http *gin.Context) {
type ParamsValidate struct {
SiteId int32 `form:"siteId" binding:"required,number"`
}

params := ParamsValidate{}
if !self.Validate(http, &params) {
return
}

taskRow, _ := dao.Task.Where(dao.Task.TaskLinkID.Eq(params.SiteId)).First()
if taskRow == nil {
self.JsonResponseWithError(http, errors.New("当前没有进行的中任务"), 500)
return
}
if taskRow.Status != logic.STATUS_PROCESSING {
self.JsonResponseWithoutError(http, gin.H{
"status": taskRow.Status,
"message": taskRow.Message,
})
return
}
task := logic.NewContainerTask()
stepLog := task.GetTaskStepLog(taskRow.TaskLinkID)
if stepLog == nil {
self.JsonResponseWithError(http, errors.New("当前没有进行的中任务或是已经完成"), 500)
return
}
self.JsonResponseWithoutError(http, gin.H{
logic.STEP_IMAGE_PULL: stepLog.GetProcess(),
})

// json := `{
// "code": 200,
// "data": {
// "imagePull": {
// "1f7ce2fa46ab": {
// "downloading": 25,
// "extracting": 0
// },
// "249ff3a7bbe6": {
// "downloading": 67,
// "extracting": 0
// },
// "33777aea940a": {
// "downloading": 0,
// "extracting": 0
// },
// "48824c101c6a": {
// "downloading": 100,
// "extracting": 0
// },
// "5dcbbe73fcf0": {
// "downloading": 0,
// "extracting": 0
// },
// "5fdd7aa4a423": {
// "downloading": 0,
// "extracting": 0
// },
// "706c00f0b7d2": {
// "downloading": 0,
// "extracting": 0
// },
// "749c44fa1213": {
// "downloading": 60,
// "extracting": 30
// },
// "8e9959c9dd31": {
// "downloading": 0,
// "extracting": 0
// },
// "92eeb6cb0068": {
// "downloading": 0,
// "extracting": 0
// },
// "9c62851e2826": {
// "downloading": 0,
// "extracting": 0
// },
// "aa5d47f22b64": {
// "downloading": 100,
// "extracting": 0
// },
// "b3a08d032c4e": {
// "downloading": 0,
// "extracting": 0
// },
// "c2e56069baaf": {
// "downloading": 0,
// "extracting": 0
// },
// "dfc8a35621ec": {
// "downloading": 0,
// "extracting": 0
// },
// "e83ad87cf6a6": {
// "downloading": 100,
// "extracting": 0
// },
// "e84c71b81827": {
// "downloading": 0,
// "extracting": 0
// },
// "f82137d66483": {
// "downloading": 0,
// "extracting": 0
// }
// }
// }
//}
//`
// http.String(200, json)
return
}

func (self Log) Run(http *gin.Context) {

}
52 changes: 37 additions & 15 deletions app/application/http/controller/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func (self Site) CreateByImage(http *gin.Context) {
Links: params.Links,
}

siteRow := &entity.Site{
SiteID: params.SiteId,
SiteName: params.SiteName,
SiteURL: params.SiteDomain,
}

err := dao.Q.Transaction(func(tx *dao.Query) error {
site, _ := tx.Site.Where(dao.Site.SiteID.Eq(params.SiteId)).First()
if site != nil {
Expand All @@ -52,12 +58,8 @@ func (self Site) CreateByImage(http *gin.Context) {
if err != nil {
return err
}
siteRow := &entity.Site{
ContainerID: containerRow.ID,
SiteID: params.SiteId,
SiteName: params.SiteName,
SiteURL: params.SiteDomain,
}

siteRow.ContainerID = containerRow.ID
err = tx.Site.Create(siteRow)
if err != nil {
return err
Expand All @@ -70,20 +72,37 @@ func (self Site) CreateByImage(http *gin.Context) {
return
}

task := logic.NewContainerTask()
taskRow := &logic.CreateMessage{
Name: params.SiteId,
Image: params.Image,
RunParams: runParams,
err = dao.Q.Transaction(func(tx *dao.Query) (err error) {
_, err = tx.Task.Where(tx.Task.TaskLinkID.Eq(siteRow.ID)).Delete()
if err != nil {
return err
}
task := logic.NewContainerTask()
runTaskRow := &logic.CreateMessage{
Name: params.SiteId,
TaskLinkId: siteRow.ID,
Image: params.Image,
RunParams: runParams,
}
task.QueueCreate <- runTaskRow
return nil
})

if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}
task.QueueCreate <- taskRow
self.JsonSuccessResponse(http)

self.JsonResponseWithoutError(http, gin.H{
"siteId": siteRow.ID,
})
return
}

func (self Site) GetList(http *gin.Context) {
type ParamsValidate struct {
Page int `form:"page,default=1" binding:"omitempty,gt=0"`
PageSize int `form:"pageSize" binding:"omitempty"`
SiteName string `form:"siteName" binding:"omitempty"`
Sort string `form:"sort,default=new" binding:"omitempty,oneof=hot new"`
}
Expand All @@ -95,13 +114,16 @@ func (self Site) GetList(http *gin.Context) {
if params.Page < 1 {
params.Page = 1
}
limit := 20
if params.PageSize < 1 {
params.PageSize = 10
}

query := dao.Site.Preload(dao.Site.Container.Select(dao.Container.ID, dao.Container.Image, dao.Container.Status))
if params.SiteName != "" {
query = query.Where(dao.Site.SiteName.Like("%" + params.SiteName + "%"))
}
list, total, _ := query.FindByPage((params.Page-1)*limit, limit)
query = query.Order(dao.Site.ID.Desc())
list, total, _ := query.FindByPage((params.Page-1)*params.PageSize, params.PageSize)
self.JsonResponseWithoutError(http, gin.H{
"total": total,
"page": params.Page,
Expand Down
Loading

0 comments on commit 38a27d6

Please sign in to comment.