Skip to content

Commit

Permalink
调整超时时间
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelmaxQm committed Apr 5, 2024
1 parent 4764e9e commit 54268de
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 59 deletions.
18 changes: 7 additions & 11 deletions server/api/v1/cloud/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,15 @@ func (s *ServerApi) Install(c *gin.Context) {
// 将新的上下文传递给需要长时间运行的操作
c.Request = c.Request.WithContext(ctx)

//docker := cloud.CmdNode{
// Cmd: "curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh",
//}

//dockerCompose := cloud.CmdNode{
// Cmd: "sudo curl -L \"https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose && docker-compose version",
//}
docker := cloud.CmdNode{
Cmd: "curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh",
}

pingTest := cloud.CmdNode{
Cmd: "ping www.baidu.com",
dockerCompose := cloud.CmdNode{
Cmd: "sudo curl -L \"https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose && docker-compose version",
}

Run([]cloud.CmdNode{pingTest}, c)
Run([]cloud.CmdNode{docker, dockerCompose}, c)

}

Expand Down Expand Up @@ -94,7 +90,7 @@ func Run(cmds []cloud.CmdNode, c *gin.Context) {
return false
}
return true
case <-time.After(1 * time.Second):
case <-time.After(3 * time.Second):
c.SSEvent(constant.PENDING, "pending:"+time.Now().String())
return true
}
Expand Down
2 changes: 1 addition & 1 deletion server/core/server_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func initServer(address string, router *gin.Engine) server {
s := endless.NewServer(address, router)
s.ReadHeaderTimeout = 20 * time.Second
s.WriteTimeout = 20 * time.Second
s.WriteTimeout = 20 * time.Minute
s.MaxHeaderBytes = 1 << 20
return s
}
2 changes: 1 addition & 1 deletion server/core/server_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func initServer(address string, router *gin.Engine) server {
Addr: address,
Handler: router,
ReadTimeout: 20 * time.Second,
WriteTimeout: 20 * time.Second,
WriteTimeout: 20 * time.Minute,
MaxHeaderBytes: 1 << 20,
}
}
3 changes: 1 addition & 2 deletions server/initialize/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
ginSwagger "github.com/swaggo/gin-swagger"
"net/http"
"os"
"time"
)

type justFilesFilesystem struct {
Expand All @@ -35,7 +34,7 @@ func (fs justFilesFilesystem) Open(name string) (http.File, error) {

func Routers() *gin.Engine {
Router := gin.New()
Router.Use(gin.Recovery(), middleware.TimeoutMiddleware(20*time.Second))
Router.Use(gin.Recovery())
if gin.Mode() == gin.DebugMode {
Router.Use(gin.Logger())
}
Expand Down
30 changes: 0 additions & 30 deletions web/src/api/sse.js

This file was deleted.

30 changes: 30 additions & 0 deletions web/src/utils/sse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { fetchEventSource } from '@microsoft/fetch-event-source'

const basePath = import.meta.env.VITE_BASE_API
export const useSSE = (url, {
onmessage,
onopen,
onclose,
onerror,
data,
headers = {
'Content-Type': 'application/json',
},
openWhenHidden = true,
}) => {
const ctrl = new AbortController()

return [ctrl, () => {
fetchEventSource(` ${basePath}${url}`, {
method: 'POST',
openWhenHidden,
headers,
body: JSON.stringify(data),
signal: ctrl.signal,
onmessage: onmessage,
onopen: onopen,
onclose: onclose,
onerror: onerror
})
}]
}
20 changes: 6 additions & 14 deletions web/src/view/cloud/public/public.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@
</template>

<script setup>
import { serverCheck } from '@/api/cloud'
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { fetchEventSource } from '@microsoft/fetch-event-source';
import { useSSE } from '@/api/sse'
import { useSSE } from '@/utils/sse'
const publicForm = ref(null)
Expand All @@ -71,17 +69,18 @@ const install = async () =>{
case 'pending':
if(cmds.value[cmds.value.length - 1]?.event !== 'pending'){
cmds.value.push({
event: 'message',
data: ev.data
event: 'pending',
data: "正在执行命令"
});
}
cmds.value[cmds.value.length - 1].data += ".";
break;
case 'complete':
cmds.value.push({
event: 'complete',
data: ev.data
});
ElMessage.success('环境安装成功')
ElMessage.success('执行完成')
break;
case 'fail':
cmds.value.push({
Expand All @@ -95,12 +94,6 @@ const install = async () =>{
data: ev.data
});
}
},
onclose(){
console.log("close")
},
onerror(err){
console.log(err)
}
})
ctrl.value = c;
Expand Down Expand Up @@ -128,8 +121,7 @@ const check = async () =>{
event: 'complete',
data: ev.data
});
Close()
ElMessage.success('检测成功')
ElMessage.success('执行完成')
break;
case 'fail':
cmds.value.push({
Expand Down

0 comments on commit 54268de

Please sign in to comment.