Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
admin-backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
admin-backend
Commits
bfc209e0
Commit
bfc209e0
authored
Apr 18, 2024
by
brent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify taskheat
parent
d5c29184
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
144 additions
and
19 deletions
+144
-19
task.go
controllers/task.go
+2
-0
user.go
controllers/user.go
+61
-0
cronjob.go
libs/cronjob/cronjob.go
+77
-19
task.go
models/task.go
+4
-0
No files found.
controllers/task.go
View file @
bfc209e0
...
@@ -2922,6 +2922,8 @@ func initTypeInRedis() []models.TaskHeat {
...
@@ -2922,6 +2922,8 @@ func initTypeInRedis() []models.TaskHeat {
OutPutJson
:
output
,
OutPutJson
:
output
,
AccessStatus
:
dbType
.
AccessStatus
,
AccessStatus
:
dbType
.
AccessStatus
,
PublishStatus
:
dbType
.
PublishStatus
,
PublishStatus
:
dbType
.
PublishStatus
,
EstimatExeTime
:
dbType
.
EstimatExeTime
,
StartUpTime
:
dbType
.
StartUpTime
,
}
}
response
=
append
(
response
,
retask
)
response
=
append
(
response
,
retask
)
}
}
...
...
controllers/user.go
View file @
bfc209e0
...
@@ -12,6 +12,8 @@ import (
...
@@ -12,6 +12,8 @@ import (
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"github.com/beego/beego/orm"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/core/logs"
beego
"github.com/beego/beego/v2/server/web"
beego
"github.com/beego/beego/v2/server/web"
"io"
"io"
...
@@ -227,6 +229,65 @@ func (server *UserController) UserInfo() {
...
@@ -227,6 +229,65 @@ func (server *UserController) UserInfo() {
server
.
respond
(
http
.
StatusOK
,
""
,
userInfo
)
server
.
respond
(
http
.
StatusOK
,
""
,
userInfo
)
}
}
func
(
server
*
UserController
)
FreeCallCount
()
{
info
,
err
:=
server
.
Check
()
if
err
!=
nil
{
server
.
respond
(
http
.
StatusUnauthorized
,
err
.
Error
())
return
}
body
:=
server
.
Ctx
.
Input
.
RequestBody
appRequest
:=
models
.
AppRequest
{}
_
=
json
.
Unmarshal
(
body
,
&
appRequest
)
//解析body中数据
logs
.
Debug
(
"appRequest"
,
appRequest
,
string
(
body
))
if
appRequest
.
Page
==
0
{
appRequest
.
Page
=
1
}
if
appRequest
.
Size
==
0
{
appRequest
.
Size
=
10
}
offset
:=
(
appRequest
.
Page
-
1
)
*
appRequest
.
Size
countQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
queryQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
countQB
.
Select
(
"count(*) AS total"
)
.
From
(
"task_type"
)
queryQB
.
Select
(
"id"
,
"name"
,
"api_path"
)
.
From
(
"task_type"
)
if
!
(
info
.
Role
==
1
||
info
.
Role
==
2
)
{
countQB
.
And
(
fmt
.
Sprintf
(
"user_id = '%d'"
,
info
.
UserID
))
queryQB
.
And
(
fmt
.
Sprintf
(
"user_id = '%d'"
,
info
.
UserID
))
}
if
appRequest
.
Keyword
!=
""
{
keyword
:=
"%"
+
appRequest
.
Keyword
+
"%"
countQB
.
And
(
fmt
.
Sprintf
(
"name like '%s'"
,
keyword
))
queryQB
.
And
(
fmt
.
Sprintf
(
"name like '%s'"
,
keyword
))
}
queryQB
.
Limit
(
int
(
appRequest
.
Size
))
.
Offset
(
int
(
offset
))
sql
:=
countQB
.
String
()
var
total
int64
_
=
mysql
.
GetMysqlInstace
()
.
Ormer
.
Raw
(
sql
)
.
QueryRow
(
&
total
)
// 导出 SQL 语句
var
taskTypes
[]
*
models
.
TaskType
sql
=
queryQB
.
String
()
mysql
.
GetMysqlInstace
()
.
Ormer
.
Raw
(
sql
)
.
QueryRows
(
&
taskTypes
)
responseData
:=
struct
{
Total
int64
`json:"total"`
Data
interface
{}
`json:"data,omitempty"`
}{
Total
:
total
,
Data
:
taskTypes
,
}
server
.
respond
(
http
.
StatusOK
,
""
,
responseData
)
}
func
regisgerUser
(
user
models
.
User
)
(
*
models
.
User
,
error
)
{
func
regisgerUser
(
user
models
.
User
)
(
*
models
.
User
,
error
)
{
var
err
error
var
err
error
qs
:=
mysql
.
GetMysqlInstace
()
.
Ormer
.
QueryTable
(
"user"
)
qs
:=
mysql
.
GetMysqlInstace
()
.
Ormer
.
QueryTable
(
"user"
)
...
...
libs/cronjob/cronjob.go
View file @
bfc209e0
package
cronjob
package
cronjob
import
(
import
(
"ai_developer_admin/libs/mysql"
"ai_developer_admin/libs/postgres"
"ai_developer_admin/libs/postgres"
"ai_developer_admin/libs/redis"
"ai_developer_admin/libs/redis"
"ai_developer_admin/libs/registry"
"ai_developer_admin/libs/registry"
...
@@ -15,6 +16,7 @@ import (
...
@@ -15,6 +16,7 @@ import (
"github.com/robfig/cron/v3"
"github.com/robfig/cron/v3"
"sort"
"sort"
"strconv"
"strconv"
"strings"
"time"
"time"
)
)
...
@@ -33,38 +35,94 @@ func Start() {
...
@@ -33,38 +35,94 @@ func Start() {
//startRegistBackend()
//startRegistBackend()
}
}
func
findTaskCount
(
counts
[]
models
.
TaskCount
,
id
string
)
int
{
for
_
,
value
:=
range
counts
{
if
strings
.
Compare
(
value
.
Type
,
id
)
==
0
{
count
,
_
:=
strconv
.
Atoi
(
value
.
Count
)
return
count
}
}
return
0
}
func
startHeatKey
()
{
func
startHeatKey
()
{
//spec := "0 0 * * * ?" //"@every 1h"
//spec := "0 0 * * * ?" //"@every 1h"
spec
:=
"@every 1h"
//"@every 1h"
spec
:=
"@every 1h"
//"@every 1h"
//spec := "*/1 * * * * ?" //"@every 1h"
//spec := "*/1 * * * * ?" //"@every 1h"
loopCronTask
.
AddFunc
(
spec
,
func
()
{
loopCronTask
.
AddFunc
(
spec
,
func
()
{
logs
.
Debug
(
"loopCronTask"
)
logs
.
Debug
(
"loopCronTask"
)
sql
:=
"SELECT type,count(type) FROM bills GROUP BY type ORDER BY count DESC;"
qs
:=
mysql
.
GetMysqlInstace
()
.
Ormer
.
QueryTable
(
"task_type"
)
tasks
,
err
:=
postgres
.
CountTasks
(
sql
)
count
,
_
:=
qs
.
Count
()
if
err
!=
nil
{
logs
.
Debug
(
"types = "
,
count
)
var
types
[]
*
models
.
TaskType
if
count
>
0
{
qs
.
All
(
&
types
)
}
else
{
return
return
}
}
dataString
,
err
:=
redis
.
GetDataToString
(
HeatKey
)
sql
:=
"SELECT type,count(type) FROM bills GROUP BY type ORDER BY count DESC;"
tasks
,
err
:=
postgres
.
CountTasks
(
sql
)
//if err != nil {
// return
//}
//dataString, err := redis.GetDataToString(HeatKey)
var
response
[]
*
models
.
TaskHeat
var
response
[]
*
models
.
TaskHeat
if
err
!=
nil
{
//if err != nil {
return
// return
}
//}
err
=
json
.
Unmarshal
([]
byte
(
dataString
),
&
response
)
//err = json.Unmarshal([]byte(dataString), &response)
if
err
!=
nil
{
//if err != nil {
return
// return
}
//}
for
_
,
value
:=
range
tasks
{
taskId
,
err
:=
strconv
.
Atoi
(
value
.
Type
)
for
_
,
dbType
:=
range
types
{
if
err
!=
nil
{
var
hardwareRequire
interface
{}
continue
eer
:=
json
.
Unmarshal
([]
byte
(
dbType
.
HardwareRequire
),
&
hardwareRequire
)
if
eer
!=
nil
{
}
}
count
,
_
:=
strconv
.
Atoi
(
value
.
Count
)
var
output
interface
{}
for
_
,
taskType
:=
range
response
{
if
dbType
.
Form
!=
""
{
if
taskType
.
TaskId
==
taskId
{
err
:=
json
.
Unmarshal
([]
byte
(
dbType
.
Form
),
&
output
)
taskType
.
Count
=
int64
(
count
)
if
err
!=
nil
{
logs
.
Debug
(
"Form Unmarshal err"
)
}
}
}
}
heat
:=
findTaskCount
(
tasks
,
strconv
.
Itoa
(
dbType
.
Id
))
retask
:=
models
.
TaskHeat
{
TaskId
:
dbType
.
Id
,
User
:
dbType
.
Username
,
Pwd
:
dbType
.
Password
,
Repository
:
dbType
.
ImageUrl
,
SignUrl
:
dbType
.
SignUrl
,
ImageName
:
dbType
.
ImageName
,
ImageId
:
dbType
.
ImageId
,
HardwareRequire
:
hardwareRequire
,
Count
:
int64
(
heat
),
Kind
:
dbType
.
Kind
,
FileExpiresTime
:
strconv
.
Itoa
(
dbType
.
ResultFileExpires
),
OutPutJson
:
output
,
AccessStatus
:
dbType
.
AccessStatus
,
PublishStatus
:
dbType
.
PublishStatus
,
EstimatExeTime
:
dbType
.
EstimatExeTime
,
StartUpTime
:
dbType
.
StartUpTime
,
}
response
=
append
(
response
,
&
retask
)
}
}
//for _, value := range tasks {
// taskId, err := strconv.Atoi(value.Type)
// if err != nil {
// continue
// }
// count, _ := strconv.Atoi(value.Count)
// for _, taskType := range response {
// if taskType.TaskId == taskId {
// taskType.Count = int64(count)
// }
// }
//}
//for _, value := range tasks {
//for _, value := range tasks {
// taskId, err := strconv.Atoi(value.Type)
// taskId, err := strconv.Atoi(value.Type)
// if err != nil {
// if err != nil {
...
...
models/task.go
View file @
bfc209e0
...
@@ -104,6 +104,7 @@ type TaskType struct {
...
@@ -104,6 +104,7 @@ type TaskType struct {
Unit
string
`json:"unit";orm:"column(unit)"`
Unit
string
`json:"unit";orm:"column(unit)"`
Sort
int
`json:"sort";orm:"column(sort)"`
Sort
int
`json:"sort";orm:"column(sort)"`
EstimatExeTime
int
`json:"estimat_exe_time";orm:"column(estimat_exe_time)"`
EstimatExeTime
int
`json:"estimat_exe_time";orm:"column(estimat_exe_time)"`
StartUpTime
int
`json:"start_up_time";orm:"column(start_up_time)"`
MaxExecTime
int
`json:"max_exec_time";orm:"column(max_exec_time)"`
MaxExecTime
int
`json:"max_exec_time";orm:"column(max_exec_time)"`
CreatedTime
time
.
Time
`json:"created_time";orm:"column(created_time);type(datetime)"`
CreatedTime
time
.
Time
`json:"created_time";orm:"column(created_time);type(datetime)"`
UpdatedTime
time
.
Time
`json:"updated_time";orm:"column(updated_time);type(datetime)"`
UpdatedTime
time
.
Time
`json:"updated_time";orm:"column(updated_time);type(datetime)"`
...
@@ -147,6 +148,7 @@ type NewTaskType struct {
...
@@ -147,6 +148,7 @@ type NewTaskType struct {
PublishStatus
int
`json:"publish_status,omitempty"`
PublishStatus
int
`json:"publish_status,omitempty"`
Unit
string
`json:"unit";orm:"column(unit)"`
Unit
string
`json:"unit";orm:"column(unit)"`
Sort
int
`json:"sort";orm:"column(sort)"`
Sort
int
`json:"sort";orm:"column(sort)"`
StartUpTime
int
`json:"start_up_time";orm:"column(start_up_time)"`
EstimatExeTime
int
`json:"estimat_exe_time";orm:"column(estimat_exe_time)"`
EstimatExeTime
int
`json:"estimat_exe_time";orm:"column(estimat_exe_time)"`
MaxExecTime
int
`json:"max_exec_time";orm:"column(max_exec_time)"`
MaxExecTime
int
`json:"max_exec_time";orm:"column(max_exec_time)"`
CreatedTime
time
.
Time
`json:"created_time";orm:"column(created_time);type(datetime)"`
CreatedTime
time
.
Time
`json:"created_time";orm:"column(created_time);type(datetime)"`
...
@@ -269,6 +271,8 @@ type TaskHeat struct {
...
@@ -269,6 +271,8 @@ type TaskHeat struct {
OutPutJson
interface
{}
`json:"out_put_json";orm:"column(out_put_json)"`
OutPutJson
interface
{}
`json:"out_put_json";orm:"column(out_put_json)"`
AccessStatus
int
`json:"access_status,omitempty"`
AccessStatus
int
`json:"access_status,omitempty"`
PublishStatus
int
`json:"publish_status,omitempty"`
PublishStatus
int
`json:"publish_status,omitempty"`
EstimatExeTime
int
`json:"estimat_exe_time"`
StartUpTime
int
`json:"start_up_time"`
}
}
type
AddTaskType
struct
{
type
AddTaskType
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment