Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gofmt #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions app/container/monitor.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package container

import (
"github.com/astaxie/beego"
"bzppx-codepub/app/models"
"github.com/astaxie/beego"
"time"
)

Expand All @@ -13,11 +13,10 @@ func NewMonitor() *Monitor {
}

type Monitor struct {

}

// 每 5 s 监控一次是否有没有提交的(暂时取消)
func (m *Monitor) MonitorCreateStatus() {
func (m *Monitor) MonitorCreateStatus() {
for {
m.HandleCreateStatusTaskLog()
time.Sleep(10 * time.Second)
Expand Down Expand Up @@ -88,21 +87,21 @@ func (m *Monitor) HandleCreateStatusTaskLog() {
sha1Id = project["branch"]
}
args := map[string]interface{}{
"task_log_id": taskLog["task_log_id"],
"url": project["repository_url"],
"ssh_key": project["ssh_key"],
"ssh_key_salt": project["ssh_key_salt"],
"path": project["code_path"],
"branch": sha1Id,
"username": project["https_username"],
"password": project["https_password"],
"dir_user": project["code_dir_user"],
"pre_command": project["pre_command"],
"pre_command_exec_type": project["pre_command_exec_type"],
"pre_command_exec_timeout": project["pre_command_exec_timeout"],
"post_command": project["post_command"],
"post_command_exec_type": project["post_command_exec_type"],
"post_command_exec_timeout": project["post_command_exec_timeout"],
"task_log_id": taskLog["task_log_id"],
"url": project["repository_url"],
"ssh_key": project["ssh_key"],
"ssh_key_salt": project["ssh_key_salt"],
"path": project["code_path"],
"branch": sha1Id,
"username": project["https_username"],
"password": project["https_password"],
"dir_user": project["code_dir_user"],
"pre_command": project["pre_command"],
"pre_command_exec_type": project["pre_command_exec_type"],
"pre_command_exec_timeout": project["pre_command_exec_timeout"],
"post_command": project["post_command"],
"post_command_exec_type": project["post_command_exec_type"],
"post_command_exec_timeout": project["post_command_exec_timeout"],
}
for _, node := range nodes {
if node["node_id"] == taskLog["node_id"] {
Expand All @@ -113,11 +112,11 @@ func (m *Monitor) HandleCreateStatusTaskLog() {
}
}
agentMessage := AgentMessage{
Ip: ip,
Port: port,
Ip: ip,
Port: port,
Token: token,
Args: args,
Args: args,
}
Worker.SendPublishChan(agentMessage)
}
}
}
42 changes: 21 additions & 21 deletions app/container/worker.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package container

import (
"bzppx-codepub/app/remotes"
"time"
"bzppx-codepub/app/models"
"bzppx-codepub/app/remotes"
"github.com/astaxie/beego"
"time"
)

var Worker = NewWorker()

type worker struct {
publishChan chan AgentMessage
statusChan chan AgentMessage
statusChan chan AgentMessage
}

type AgentMessage struct {
Ip string
Port string
Ip string
Port string
Token string
Args map[string]interface{}
Args map[string]interface{}
}

func NewWorker() *worker {
return &worker{
publishChan: make(chan AgentMessage, 1),
statusChan: make(chan AgentMessage, 1),
statusChan: make(chan AgentMessage, 1),
}
}

func (w *worker) SendPublishChan(agentMsg AgentMessage) {
func (w *worker) SendPublishChan(agentMsg AgentMessage) {
w.publishChan <- agentMsg
}

func (w *worker) SendGetStatusChan(agentMsg AgentMessage) {
func (w *worker) SendGetStatusChan(agentMsg AgentMessage) {
w.statusChan <- agentMsg
}

Expand All @@ -52,7 +52,7 @@ func (w *worker) StartPublish() {
if err != nil {
beego.Error(err.Error())
w.PublishFailed(agentMsg.Args["task_log_id"].(string), err.Error())
}else {
} else {
w.SendGetStatusChan(agentMsg)
}
}(agentMsg)
Expand All @@ -73,7 +73,7 @@ func (w *worker) StartGetStatus() {
}
}()
for {
isFinish, err := remotes.Task.GetResults(agentMsg.Ip, agentMsg.Port, agentMsg.Token,agentMsg.Args)
isFinish, err := remotes.Task.GetResults(agentMsg.Ip, agentMsg.Port, agentMsg.Token, agentMsg.Args)
if err != nil {
beego.Error(err.Error())
w.UpdateResult(agentMsg.Args["task_log_id"].(string), err.Error())
Expand All @@ -90,31 +90,31 @@ func (w *worker) StartGetStatus() {

func (t *worker) UpdateResult(taskLogId string, result string) {
update := map[string]interface{}{
"result": result,
"result": result,
"update_time": time.Now().Unix(),
}
_, err := models.TaskLogModel.Update(taskLogId, update)
if err != nil {
beego.Error("update task_log result error: "+ err.Error())
beego.Error("update task_log result error: " + err.Error())
}
}

func (t *worker) PublishFailed(taskLogId string, result string) {
func (t *worker) PublishFailed(taskLogId string, result string) {
taskLogValue := map[string]interface{}{
"status": models.TASKLOG_STATUS_FINISH,
"is_success": models.TASKLOG_FAILED,
"result": result,
"commit_id": "",
"status": models.TASKLOG_STATUS_FINISH,
"is_success": models.TASKLOG_FAILED,
"result": result,
"commit_id": "",
"update_time": time.Now().Unix(),
}
_, err := models.TaskLogModel.Update(taskLogId, taskLogValue)
if err != nil {
beego.Error("update task_log public failed error: "+ err.Error())
beego.Error("update task_log public failed error: " + err.Error())
}
}

// 初始化
func InitWorker() {
func InitWorker() {
go func() {
defer func() {
err := recover()
Expand Down Expand Up @@ -142,4 +142,4 @@ func InitWorker() {
}()
NewMonitor().HandleCreateStatusTaskLog()
}()
}
}
3 changes: 2 additions & 1 deletion app/controllers/data.go

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions app/controllers/group.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package controllers

import (
"strings"
"bzppx-codepub/app/models"
"time"
"bzppx-codepub/app/utils"
"strings"
"time"
)

type GroupController struct {
Expand All @@ -28,50 +28,50 @@ func (this *GroupController) Save() {

group, err := models.GroupModel.HasGroupName(name)
if err != nil {
this.ErrorLog("查找项目组 "+name+" 失败:"+err.Error())
this.ErrorLog("查找项目组 " + name + " 失败:" + err.Error())
this.jsonError("添加项目组失败!")
}
if group {
this.jsonError("项目组名称已存在!")
}

groupValue := map[string]interface{}{
"name": name,
"comment": comment,
"name": name,
"comment": comment,
"create_time": time.Now().Unix(),
"update_time": time.Now().Unix(),
}

groupId, err := models.GroupModel.Insert(groupValue)
if err != nil {
this.ErrorLog("添加项目组失败: "+err.Error())
this.ErrorLog("添加项目组失败: " + err.Error())
this.jsonError("添加项目组失败!")
}else {
this.InfoLog("添加项目组 "+utils.NewConvert().IntToString(groupId, 10)+" 成功")
} else {
this.InfoLog("添加项目组 " + utils.NewConvert().IntToString(groupId, 10) + " 成功")
this.jsonSuccess("添加项目组成功", nil, "/group/list")
}
}

// 项目组列表
func (this *GroupController) List() {

page, _:= this.GetInt("page", 1)
page, _ := this.GetInt("page", 1)
keyword := strings.Trim(this.GetString("keyword", ""), "")

number := 20
limit := (page - 1) * number
var err error
var count int64
var groups []map[string]string
if (keyword != "") {
if keyword != "" {
count, err = models.GroupModel.CountGroupsByKeyword(keyword)
groups, err = models.GroupModel.GetGroupsByKeywordAndLimit(keyword, limit, number)
}else {
} else {
count, err = models.GroupModel.CountGroups()
groups, err = models.GroupModel.GetGroupsByLimit(limit, number)
}
if err != nil {
this.ErrorLog("查找项目组列表失败:"+err.Error())
this.ErrorLog("查找项目组列表失败:" + err.Error())
this.viewError("查找项目组列表失败", "/group/list")
}

Expand All @@ -91,7 +91,7 @@ func (this *GroupController) Edit() {

group, err := models.GroupModel.GetGroupByGroupId(groupId)
if err != nil {
this.ErrorLog("查找项目组 "+groupId+" 失败:"+err.Error())
this.ErrorLog("查找项目组 " + groupId + " 失败:" + err.Error())
this.viewError("项目组不存在", "/group/list")
}

Expand All @@ -111,24 +111,24 @@ func (this *GroupController) Modify() {

group, err := models.GroupModel.GetGroupByGroupId(groupId)
if err != nil {
this.ErrorLog("查找项目组 "+groupId+" 失败:"+err.Error())
this.ErrorLog("查找项目组 " + groupId + " 失败:" + err.Error())
this.jsonError("项目组不存在!")
}
if len(group) == 0 {
this.jsonError("项目组不存在!")
}

groupValue := map[string]interface{}{
"comment": comment,
"comment": comment,
"update_time": time.Now().Unix(),
}

_, err = models.GroupModel.Update(groupId, groupValue)
if err != nil {
this.ErrorLog("修改项目组 "+groupId+" 失败: "+err.Error())
this.ErrorLog("修改项目组 " + groupId + " 失败: " + err.Error())
this.jsonError("修改项目组失败!")
}else {
this.InfoLog("修改项目组 "+groupId+" 成功")
} else {
this.InfoLog("修改项目组 " + groupId + " 成功")
this.jsonSuccess("修改项目组成功", nil, "/group/list")
}
}
Expand All @@ -144,7 +144,7 @@ func (this *GroupController) Delete() {

group, err := models.GroupModel.GetGroupByGroupId(groupId)
if err != nil {
this.ErrorLog("查找项目组 "+groupId+" 失败:"+err.Error())
this.ErrorLog("查找项目组 " + groupId + " 失败:" + err.Error())
this.jsonError("项目组不存在!")
}
if len(group) == 0 {
Expand All @@ -154,16 +154,16 @@ func (this *GroupController) Delete() {
// todo 判断项目组下的项目是否需要一起删除

groupValue := map[string]interface{}{
"is_delete": models.GROUP_DELETE,
"is_delete": models.GROUP_DELETE,
"update_time": time.Now().Unix(),
}

_, err = models.GroupModel.Update(groupId, groupValue)
if err != nil {
this.ErrorLog("删除项目组 "+groupId+" 失败: "+err.Error())
this.ErrorLog("删除项目组 " + groupId + " 失败: " + err.Error())
this.jsonError("删除项目组失败!")
}

this.InfoLog("删除项目组 "+groupId+" 成功")
this.InfoLog("删除项目组 " + groupId + " 成功")
this.jsonSuccess("删除项目组成功", nil, "/group/list")
}
}
2 changes: 1 addition & 1 deletion app/controllers/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (this *LogController) Task() {
if err != nil {
this.viewError(err.Error(), "/log/task")
}

tasklogsChangeKey := make(map[string]map[int]map[string]string)
for index, taskLog := range taskLogs {
_, ok := tasklogsChangeKey[taskLog["task_id"]]
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package controllers

import (
"bzppx-codepub/app/models"
"bzppx-codepub/app/remotes"
"bzppx-codepub/app/utils"
"encoding/json"
"fmt"
"regexp"
"strings"
"time"
"encoding/json"
"bzppx-codepub/app/remotes"
"sync"
"fmt"
"time"
)

type NodeController struct {
Expand Down Expand Up @@ -316,9 +316,9 @@ func (this *NodeController) Status() {
this.jsonError(err.Error())
}

type Data struct{
type Data struct {
NodesStatus []map[string]interface{}
Lock sync.Mutex
Lock sync.Mutex
}
data := new(Data)
var wait sync.WaitGroup
Expand All @@ -335,14 +335,14 @@ func (this *NodeController) Status() {
}()
nodeStatus := map[string]interface{}{
"node_id": node["node_id"],
"status": 1,
"status": 1,
"version": "null",
}
res, err := remotes.System.Ping(node["ip"], node["port"], node["token"], nil)
if err != nil {
this.ErrorLog("节点 "+node["node_id"]+" 连接失败:" + err.Error())
this.ErrorLog("节点 " + node["node_id"] + " 连接失败:" + err.Error())
nodeStatus["status"] = 0
}else {
} else {
nodeStatus["version"] = res["version"]
}
data.Lock.Lock()
Expand All @@ -353,4 +353,4 @@ func (this *NodeController) Status() {

wait.Wait()
this.jsonSuccess("ok", data.NodesStatus)
}
}
Loading