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
18776250
Commit
18776250
authored
Feb 22, 2024
by
brent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add task type manager
parent
5efb81a1
Changes
17
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
1276 additions
and
178 deletions
+1276
-178
kong.conf
conf/kong.conf
+3
-0
mysql.conf
conf/mysql.conf
+6
-5
postgres.conf
conf/postgres.conf
+7
-0
redis.conf
conf/redis.conf
+9
-0
task.go
controllers/task.go
+855
-97
userlevel.go
controllers/userlevel.go
+5
-2
lastupdate.tmp
lastupdate.tmp
+1
-0
cronjob.go
libs/cronjob/cronjob.go
+94
-23
mysql.go
libs/mysql/mysql.go
+1
-0
odysseus.go
libs/odysseus/odysseus.go
+5
-0
postgres.go
libs/postgres/postgres.go
+23
-0
redis.go
libs/redis/redis.go
+58
-0
util.go
libs/utils/util.go
+24
-0
main.go
main.go
+24
-0
app.go
models/app.go
+8
-8
task.go
models/task.go
+152
-42
user.go
models/user.go
+1
-1
No files found.
conf/kong.conf
View file @
18776250
[
dev
]
[
dev
]
kongadminurl
=
"http://192.168.1.10:8001"
kongadminurl
=
"http://192.168.1.10:8001"
[
test
]
kongadminurl
=
"http://43.198.252.255:8001"
[
prod
]
[
prod
]
kongadminurl
=
"http://172.31.12.187:8001"
kongadminurl
=
"http://172.31.12.187:8001"
\ No newline at end of file
conf/mysql.conf
View file @
18776250
...
@@ -5,11 +5,12 @@ mysqlhost = "192.168.1.211"
...
@@ -5,11 +5,12 @@ mysqlhost = "192.168.1.211"
mysqlport
=
3306
mysqlport
=
3306
mysqldb
=
"liuxuzhong"
mysqldb
=
"liuxuzhong"
;
mysqluser
=
"ai"
[
test
]
;
mysqlpass
=
"RFnnKHRar5xk7TEF"
mysqluser
=
"ai"
;
mysqlhost
=
"43.198.252.255"
mysqlpass
=
"RFnnKHRar5xk7TEF"
;
mysqlport
=
3306
mysqlhost
=
"43.198.252.255"
;
mysqldb
=
"ai"
mysqlport
=
3306
mysqldb
=
"ai"
[
prod
]
[
prod
]
mysqluser
=
"ai"
mysqluser
=
"ai"
...
...
conf/postgres.conf
View file @
18776250
...
@@ -5,6 +5,13 @@ postgreshost = "192.168.1.10"
...
@@ -5,6 +5,13 @@ postgreshost = "192.168.1.10"
postgresport
=
8812
postgresport
=
8812
postgresdb
=
"qdb"
postgresdb
=
"qdb"
[
test
]
postgresuser
=
"admin"
postgrespass
=
"quest"
postgreshost
=
"43.198.252.255"
postgresport
=
8812
postgresdb
=
"qdb"
[
prod
]
[
prod
]
postgresuser
=
"admin"
postgresuser
=
"admin"
postgrespass
=
"quest"
postgrespass
=
"quest"
...
...
conf/redis.conf
View file @
18776250
...
@@ -7,6 +7,15 @@ balancehost = "192.168.1.10:6379"
...
@@ -7,6 +7,15 @@ balancehost = "192.168.1.10:6379"
balancedb
=
0
balancedb
=
0
balancepass
=
""
balancepass
=
""
[
test
]
tokenhost
=
"43.198.252.255:6379"
tokendb
=
0
tokenpass
=
"iH0g2CqzjI6SfercGwsT"
balancehost
=
"43.198.252.255:6379"
balancedb
=
0
balancepass
=
"iH0g2CqzjI6SfercGwsT"
[
prod
]
[
prod
]
tokenhost
=
"172.31.12.187:6379"
tokenhost
=
"172.31.12.187:6379"
...
...
controllers/task.go
View file @
18776250
This diff is collapsed.
Click to expand it.
controllers/userlevel.go
View file @
18776250
...
@@ -19,7 +19,7 @@ func (server *UserLevelController) Levels() {
...
@@ -19,7 +19,7 @@ func (server *UserLevelController) Levels() {
server
.
respond
(
http
.
StatusUnauthorized
,
err
.
Error
())
server
.
respond
(
http
.
StatusUnauthorized
,
err
.
Error
())
return
return
}
}
qs
:=
mysql
.
GetMysqlInstace
()
.
Ormer
.
QueryTable
(
"user_level"
)
qs
:=
mysql
.
GetMysqlInstace
()
.
Ormer
.
QueryTable
(
"user_level"
)
.
Filter
(
"deleted"
,
0
)
count
,
err
:=
qs
.
Count
()
count
,
err
:=
qs
.
Count
()
logs
.
Debug
(
"Levels = "
,
count
)
logs
.
Debug
(
"Levels = "
,
count
)
var
levels
[]
*
models
.
UserLevel
var
levels
[]
*
models
.
UserLevel
...
@@ -101,6 +101,8 @@ func (server *UserLevelController) UpdateLevel() {
...
@@ -101,6 +101,8 @@ func (server *UserLevelController) UpdateLevel() {
return
return
}
}
request
.
CreatedTime
=
checkLevel
.
CreatedTime
request
.
UpdatedTime
=
time
.
Now
()
_
,
err
=
mysql
.
GetMysqlInstace
()
.
Ormer
.
Update
(
&
request
)
_
,
err
=
mysql
.
GetMysqlInstace
()
.
Ormer
.
Update
(
&
request
)
if
err
!=
nil
{
if
err
!=
nil
{
server
.
respond
(
models
.
BusinessFailed
,
"更新失败"
)
server
.
respond
(
models
.
BusinessFailed
,
"更新失败"
)
...
@@ -135,7 +137,8 @@ func (server *UserLevelController) DelLevel() {
...
@@ -135,7 +137,8 @@ func (server *UserLevelController) DelLevel() {
server
.
respond
(
models
.
MissingParameter
,
"默认等级不能删除"
)
server
.
respond
(
models
.
MissingParameter
,
"默认等级不能删除"
)
return
return
}
}
request
.
Deleted
=
1
mysql
.
GetMysqlInstace
()
.
Ormer
.
Dele
te
(
&
request
)
mysql
.
GetMysqlInstace
()
.
Ormer
.
Upda
te
(
&
request
)
server
.
respond
(
http
.
StatusOK
,
"删除成功"
)
server
.
respond
(
http
.
StatusOK
,
"删除成功"
)
}
}
lastupdate.tmp
0 → 100755
View file @
18776250
{"/Users/brent/Documents/wubanWork/ai_developer_admin/controllers":1708598583449330754}
\ No newline at end of file
libs/cronjob/cronjob.go
View file @
18776250
package
cronjob
package
cronjob
import
(
import
(
"ai_developer_admin/libs/odysseus"
"ai_developer_admin/libs/postgres"
"ai_developer_admin/libs/postgres"
"ai_developer_admin/libs/redis"
"ai_developer_admin/libs/redis"
"ai_developer_admin/models"
"ai_developer_admin/models"
...
@@ -13,10 +12,14 @@ import (
...
@@ -13,10 +12,14 @@ import (
var
loopCronTask
=
cron
.
New
(
cron
.
WithSeconds
())
var
loopCronTask
=
cron
.
New
(
cron
.
WithSeconds
())
var
HeatKey
=
"task:heat"
func
Start
()
{
func
Start
()
{
//defer loopCronTask.Stop()
//defer loopCronTask.Stop()
spec
:=
"0 0 * * * ?"
//"@every 1h"
//spec := "0 0 * * * ?" //"@every 1h"
spec
:=
"@every 1h"
//"@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;"
sql
:=
"SELECT type,count(type) FROM bills GROUP BY type ORDER BY count DESC;"
...
@@ -24,39 +27,107 @@ func Start() {
...
@@ -24,39 +27,107 @@ func Start() {
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
dataString
,
err
:=
redis
.
GetDataToString
(
HeatKey
)
var
response
[]
models
.
TaskHeat
var
response
[]
models
.
TaskHeat
if
err
!=
nil
{
return
}
err
=
json
.
Unmarshal
([]
byte
(
dataString
),
&
response
)
if
err
!=
nil
{
return
}
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
{
continue
continue
}
}
taskType
,
err1
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
count
,
_
:=
strconv
.
Atoi
(
value
.
Count
)
if
err1
!=
nil
{
for
_
,
taskType
:=
range
response
{
continue
if
taskType
.
TaskId
==
taskId
{
taskType
.
Count
=
int64
(
count
)
}
}
var
hardwareRequire
models
.
Hardware
eer
:=
json
.
Unmarshal
([]
byte
(
taskType
.
HardwareRequire
),
&
hardwareRequire
)
if
eer
!=
nil
{
}
}
count
,
_
:=
strconv
.
Atoi
(
value
.
Count
)
retask
:=
models
.
TaskHeat
{
TaskId
:
taskId
,
User
:
taskType
.
Username
,
Pwd
:
taskType
.
Password
,
Repository
:
taskType
.
ImageUrl
,
SignUrl
:
taskType
.
SignUrl
,
ImageName
:
taskType
.
ImageName
,
ImageId
:
taskType
.
ImageId
,
HardwareRequire
:
hardwareRequire
,
Count
:
int64
(
count
),
}
response
=
append
(
response
,
retask
)
}
}
//for _, value := range tasks {
// taskId, err := strconv.Atoi(value.Type)
// if err != nil {
// continue
// }
// taskType, err1 := odysseus.GetTaskType(int64(taskId))
// if err1 != nil {
// continue
// }
// var hardwareRequire models.Hardware
// eer := json.Unmarshal([]byte(taskType.HardwareRequire), &hardwareRequire)
// if eer != nil {
//
// }
// count, _ := strconv.Atoi(value.Count)
// retask := models.TaskHeat{
// TaskId: taskId,
// User: taskType.Username,
// Pwd: taskType.Password,
// Repository: taskType.ImageUrl,
// SignUrl: taskType.SignUrl,
// ImageName: taskType.ImageName,
// ImageId: taskType.ImageId,
// HardwareRequire: hardwareRequire,
// Count: int64(count),
// }
// response = append(response, retask)
//}
data
,
err
:=
json
.
Marshal
(
response
)
data
,
err
:=
json
.
Marshal
(
response
)
if
err
==
nil
{
if
err
==
nil
{
redis
.
SetKeyAndData
(
"task:heat"
,
string
(
data
),
0
)
redis
.
SetKeyAndData
(
HeatKey
,
string
(
data
),
0
)
}
}
})
})
loopCronTask
.
Start
()
loopCronTask
.
Start
()
}
}
//func Start() {
// //defer loopCronTask.Stop()
//
// spec := "*/1 * * * * ?" //"@every 1h"
// loopCronTask.AddFunc(spec, func() {
// logs.Debug("loopCronTask")
// //sql := "SELECT type,count(type) FROM bills GROUP BY type ORDER BY count DESC;"
// //tasks, err := postgres.CountTasks(sql)
// //if err != nil {
// // return
// //}
// var response []models.TaskHeat
// //for _, value := range tasks {
// // taskId, err := strconv.Atoi(value.Type)
// // if err != nil {
// // continue
// // }
// taskType, err1 := odysseus.GetTaskType(int64(12))
// if err1 != nil {
// //continue
// }
// var hardwareRequire models.Hardware
// eer := json.Unmarshal([]byte(taskType.HardwareRequire), &hardwareRequire)
// if eer != nil {
//
// }
// //count, _ := strconv.Atoi(value.Count)
// retask := models.TaskHeat{
// TaskId: 12,
// User: taskType.Username,
// Pwd: taskType.Password,
// Repository: taskType.ImageUrl,
// SignUrl: taskType.SignUrl,
// ImageName: taskType.ImageName,
// ImageId: taskType.ImageId,
// HardwareRequire: hardwareRequire,
// Count: int64(0),
// }
// response = append(response, retask)
// //}
// data, err := json.Marshal(response)
// if err == nil {
// redis.SetKeyAndData("task:heat", string(data), 0)
// }
// })
// loopCronTask.Start()
//}
libs/mysql/mysql.go
View file @
18776250
...
@@ -28,6 +28,7 @@ func GetMysqlInstace() *Singleton {
...
@@ -28,6 +28,7 @@ func GetMysqlInstace() *Singleton {
func
init
()
{
func
init
()
{
logs
.
Debug
(
"mysql lib init"
)
logs
.
Debug
(
"mysql lib init"
)
//return
orm
.
Debug
=
true
orm
.
Debug
=
true
if
err
:=
orm
.
RegisterDriver
(
"mysql"
,
orm
.
DRMySQL
);
err
!=
nil
{
if
err
:=
orm
.
RegisterDriver
(
"mysql"
,
orm
.
DRMySQL
);
err
!=
nil
{
logs
.
Error
(
err
.
Error
())
logs
.
Error
(
err
.
Error
())
...
...
libs/odysseus/odysseus.go
View file @
18776250
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
var
syncinfo
*
cachedata
.
CacheData
var
syncinfo
*
cachedata
.
CacheData
func
init
()
{
func
init
()
{
//return
host
,
_
:=
beego
.
AppConfig
.
String
(
"balancehost"
)
host
,
_
:=
beego
.
AppConfig
.
String
(
"balancehost"
)
db
,
_
:=
beego
.
AppConfig
.
Int
(
"balancedb"
)
db
,
_
:=
beego
.
AppConfig
.
Int
(
"balancedb"
)
pass
,
_
:=
beego
.
AppConfig
.
String
(
"balancepass"
)
pass
,
_
:=
beego
.
AppConfig
.
String
(
"balancepass"
)
...
@@ -60,3 +61,7 @@ func GetUserBalance(id int64) (int64, error) {
...
@@ -60,3 +61,7 @@ func GetUserBalance(id int64) (int64, error) {
func
GetTaskType
(
id
int64
)
(
*
model
.
TaskType
,
error
)
{
func
GetTaskType
(
id
int64
)
(
*
model
.
TaskType
,
error
)
{
return
syncinfo
.
GetTaskWithId
(
id
)
return
syncinfo
.
GetTaskWithId
(
id
)
}
}
func
PublichTaskUpdate
(
path
string
)
error
{
return
syncinfo
.
PublichTaskUpdate
(
path
)
}
libs/postgres/postgres.go
View file @
18776250
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
var
ormpost
orm
.
Ormer
var
ormpost
orm
.
Ormer
func
init
()
{
func
init
()
{
//return
logs
.
Debug
(
"postgres lib init"
)
logs
.
Debug
(
"postgres lib init"
)
orm
.
Debug
=
true
orm
.
Debug
=
true
if
err
:=
orm
.
RegisterDriver
(
"postgres"
,
orm
.
DRPostgres
);
err
!=
nil
{
if
err
:=
orm
.
RegisterDriver
(
"postgres"
,
orm
.
DRPostgres
);
err
!=
nil
{
...
@@ -55,6 +56,28 @@ func init() {
...
@@ -55,6 +56,28 @@ func init() {
}
}
}
}
func
QueryTset
(
sql
string
,
args
...
interface
{})
([]
models
.
Bills
,
error
)
{
logs
.
Debug
(
"QueryBills = "
,
sql
)
qs
:=
ormpost
.
Raw
(
sql
,
args
)
var
params
[]
orm
.
Params
_
,
err
:=
qs
.
Values
(
&
params
)
if
err
!=
nil
{
return
nil
,
err
}
arr
,
err
:=
json
.
Marshal
(
params
)
if
err
!=
nil
{
return
nil
,
err
}
var
containers
[]
models
.
Bills
logs
.
Debug
(
"QueryBills = "
,
string
(
arr
))
err
=
json
.
Unmarshal
(
arr
,
&
containers
)
if
err
!=
nil
{
return
nil
,
err
}
return
containers
,
nil
}
func
QueryBills
(
sql
string
)
([]
models
.
Bills
,
error
)
{
func
QueryBills
(
sql
string
)
([]
models
.
Bills
,
error
)
{
logs
.
Debug
(
"QueryBills = "
,
sql
)
logs
.
Debug
(
"QueryBills = "
,
sql
)
qs
:=
ormpost
.
Raw
(
sql
)
qs
:=
ormpost
.
Raw
(
sql
)
...
...
libs/redis/redis.go
View file @
18776250
package
redis
package
redis
import
(
import
(
"fmt"
"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"
"github.com/google/uuid"
"gopkg.in/redis.v5"
"gopkg.in/redis.v5"
"strconv"
"strings"
"time"
"time"
)
)
var
redisCache
*
redis
.
Client
var
redisCache
*
redis
.
Client
func
init
()
{
func
init
()
{
//return
host
,
_
:=
beego
.
AppConfig
.
String
(
"tokenhost"
)
host
,
_
:=
beego
.
AppConfig
.
String
(
"tokenhost"
)
db
,
_
:=
beego
.
AppConfig
.
Int
(
"tokendb"
)
db
,
_
:=
beego
.
AppConfig
.
Int
(
"tokendb"
)
pass
,
_
:=
beego
.
AppConfig
.
String
(
"tokenpass"
)
pass
,
_
:=
beego
.
AppConfig
.
String
(
"tokenpass"
)
...
@@ -31,6 +36,59 @@ func createClient(redisHost string, password string, dataBase int) *redis.Client
...
@@ -31,6 +36,59 @@ func createClient(redisHost string, password string, dataBase int) *redis.Client
return
client
return
client
}
}
func
tryAcquire
(
rs
*
redis
.
Client
,
lockKey
string
,
lockTimeout
time
.
Duration
)
(
acquired
bool
,
release
func
(),
_
error
)
{
timeout
:=
time
.
Now
()
.
Add
(
lockTimeout
)
.
UnixNano
()
lockToken
:=
fmt
.
Sprintf
(
"%d,%s"
,
timeout
,
uuid
.
New
()
.
String
())
release
=
func
()
{
// Best effort to check we're releasing the lock we think we have. Note that it
// is still technically possible the lock token has changed between the GET and
// DEL since these are two separate operations, i.e. when the current lock happen
// to be expired at this very moment.
get
,
_
:=
rs
.
Get
(
lockKey
)
.
Result
()
if
get
==
lockToken
{
_
=
rs
.
Del
(
lockKey
)
}
}
set
,
err
:=
rs
.
SetNX
(
lockKey
,
lockToken
,
lockTimeout
)
.
Result
()
if
err
!=
nil
{
return
false
,
nil
,
err
}
else
if
set
{
return
true
,
release
,
nil
}
// We didn't get the lock, but we can check if the lock is expired.
currentLockToken
,
err
:=
rs
.
Get
(
lockKey
)
.
Result
()
if
err
==
redis
.
Nil
{
// Someone else got the lock and released it already.
return
false
,
nil
,
nil
}
else
if
err
!=
nil
{
return
false
,
nil
,
err
}
currentTimeout
,
_
:=
strconv
.
ParseInt
(
strings
.
SplitN
(
currentLockToken
,
","
,
2
)[
0
],
10
,
64
)
if
currentTimeout
>
time
.
Now
()
.
UnixNano
()
{
// The lock is still valid.
return
false
,
nil
,
nil
}
// The lock has expired, try to acquire it.
get
,
err
:=
rs
.
GetSet
(
lockKey
,
lockToken
)
.
Result
()
if
err
!=
nil
{
return
false
,
nil
,
err
}
else
if
get
!=
currentLockToken
{
// Someone else got the lock
return
false
,
nil
,
nil
}
// We got the lock.
return
true
,
release
,
nil
}
func
SetHeat
(
key
string
,
value
interface
{},
time
time
.
Duration
)
{
}
func
SetKeyAndData
(
key
string
,
value
interface
{},
time
time
.
Duration
)
error
{
func
SetKeyAndData
(
key
string
,
value
interface
{},
time
time
.
Duration
)
error
{
err
:=
redisCache
.
Set
(
key
,
value
,
time
)
.
Err
()
err
:=
redisCache
.
Set
(
key
,
value
,
time
)
.
Err
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
libs/utils/util.go
0 → 100644
View file @
18776250
package
utils
import
"time"
func
InSameDay
(
t1
,
t2
time
.
Time
)
bool
{
y1
,
m1
,
d1
:=
t1
.
Date
()
y2
,
m2
,
d2
:=
t2
.
Date
()
return
y1
==
y2
&&
m1
==
m2
&&
d1
==
d2
}
func
SplitDate
(
beginDate
,
endDate
,
format
string
)
[]
string
{
bDate
,
_
:=
time
.
ParseInLocation
(
format
,
beginDate
,
time
.
Local
)
eDate
,
_
:=
time
.
ParseInLocation
(
format
,
endDate
,
time
.
Local
)
day
:=
int
(
eDate
.
Sub
(
bDate
)
.
Hours
()
/
24
)
dlist
:=
make
([]
string
,
0
)
dlist
=
append
(
dlist
,
beginDate
)
for
i
:=
1
;
i
<
day
;
i
++
{
result
:=
bDate
.
AddDate
(
0
,
0
,
i
)
dlist
=
append
(
dlist
,
result
.
Format
(
format
))
}
dlist
=
append
(
dlist
,
endDate
)
return
dlist
}
main.go
View file @
18776250
...
@@ -4,9 +4,11 @@ import (
...
@@ -4,9 +4,11 @@ import (
"ai_developer_admin/libs/cronjob"
"ai_developer_admin/libs/cronjob"
"ai_developer_admin/libs/mysql"
"ai_developer_admin/libs/mysql"
_
"ai_developer_admin/routers"
_
"ai_developer_admin/routers"
"fmt"
beego
"github.com/beego/beego/v2/server/web"
beego
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/filter/cors"
"github.com/beego/beego/v2/server/web/filter/cors"
_
"github.com/beego/beego/v2/server/web/session/redis"
_
"github.com/beego/beego/v2/server/web/session/redis"
"time"
)
)
func
init
()
{
func
init
()
{
...
@@ -34,6 +36,28 @@ func main() {
...
@@ -34,6 +36,28 @@ func main() {
// logs.SetLogger(logs.AdapterFile, config)
// logs.SetLogger(logs.AdapterFile, config)
//}
//}
str
:=
"2024-02-01T18:41:30"
layout
:=
"2006-01-02T15:04:05"
t
,
_
:=
time
.
Parse
(
layout
,
str
)
fmt
.
Print
(
"t = %s"
,
t
)
//currentTime := time.Now()
////if appRequest.EndTime == nil {
//tempendTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location())
//endTime := &tempendTime
////}
////if appRequest.StartTime == nil {
//temp := fmt.Sprintf("-%dh", 24*7)
//m, _ := time.ParseDuration(temp)
//tempTime := currentTime.Add(m)
//tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location())
//startTime := &tempTime
////}
//startTimeStr := fmt.Sprintf(startTime.Format("2006-01-02T15:04:05.000000Z"))
//endTimeStr := fmt.Sprintf(endTime.Format("2006-01-02T15:04:05.000000Z"))
//
//dates := utils.SplitDate(startTimeStr, endTimeStr, "2006-01-02T15:04:05.000000Z")
//logs.Debug("dates = ", dates)
cronjob
.
Start
()
cronjob
.
Start
()
mysql
.
GetMysqlInstace
()
mysql
.
GetMysqlInstace
()
//postgres.Query("")
//postgres.Query("")
...
...
models/app.go
View file @
18776250
...
@@ -43,8 +43,8 @@ type AppRequest struct {
...
@@ -43,8 +43,8 @@ type AppRequest struct {
Name
string
`json:"name,omitempty"`
Name
string
`json:"name,omitempty"`
Page
int64
`json:"page,omitempty"`
Page
int64
`json:"page,omitempty"`
Size
int64
`json:"size,omitempty"`
Size
int64
`json:"size,omitempty"`
StartTime
*
time
.
Time
`json:"start_time,omitempty"`
StartTime
string
`json:"start_time,omitempty"`
EndTime
*
time
.
Time
`json:"end_time,omitempty"`
EndTime
string
`json:"end_time,omitempty"`
ProfitAcc
string
`json:"profit_acc,omitempty"`
ProfitAcc
string
`json:"profit_acc,omitempty"`
WorkerAcc
string
`json:"worker_acc,omitempty"`
WorkerAcc
string
`json:"worker_acc,omitempty"`
}
}
models/task.go
View file @
18776250
...
@@ -4,26 +4,42 @@ import (
...
@@ -4,26 +4,42 @@ import (
"time"
"time"
)
)
type
Hardware
struct
{
//type Hardware struct {
DiskSize
int64
`json:"disk_size,omitempty"`
// DiskSize int64 `json:"disk_size,omitempty"`
MemorySize
int64
`json:"memory_size,omitempty"`
// MemorySize int64 `json:"memory_size,omitempty"`
Gpus
[]
string
`json:"gpus,omitempty"`
// Gpus []string `json:"gpus,omitempty"`
}
//}
//
//type CMD struct {
// ImageName string `json:"image_name"`
// DockerCmd struct {
// ContainerPort string `json:"container_port"`
// } `json:"docker_cmd"`
// ApiUrl string `json:"api_url"`
//}
type
CMD
struct
{
type
ExampleType
struct
{
ImageName
string
`json:"image_name"`
Title
string
`json:"title"`
DockerCmd
struct
{
Input
struct
{
ContainerPort
string
`json:"container_port"`
Prompt
string
`json:"prompt,omitempty"`
}
`json:"docker_cmd"`
Image
string
`json:"image,omitempty"`
ApiUrl
string
`json:"api_url"`
}
`json:"input"`
Output
struct
{
Text
string
`json:"text,omitempty"`
Url
string
`json:"url,omitempty"`
}
`json:"output"`
}
}
type
TaskType
struct
{
type
TaskType
struct
{
Id
int
`orm:"column(id);auto"`
Id
int
`orm:"column(id);auto"`
Name
string
`json:"name";orm:"column(name);size(20)"`
Version
string
`json:"version,omitempty";orm:"column(version)"`
Desc
string
`json:"desc";orm:"column(desc);size(20)"`
Desc
string
`json:"desc";orm:"column(desc);size(20)"`
Price
int64
`json:"price";orm:"column(price)"`
Price
int64
`json:"price";orm:"column(price)"`
PublicKey
string
`json:"public_key";orm:"column(public_key)"`
PublicKey
string
`json:"public_key";orm:"column(public_key)"`
Complexity
int
`json:"complexity";orm:"column(complexity)"`
Complexity
int
`json:"complexity";orm:"column(complexity)"`
Type
int
`json:"type";orm:"column(type)"`
Kind
int
`json:"kind";orm:"column(kind)"`
HardwareRequire
string
`json:"hardware_require";orm:"column(hardware_require)"`
HardwareRequire
string
`json:"hardware_require";orm:"column(hardware_require)"`
ImageId
string
`json:"image_id";orm:"column(image_id)"`
ImageId
string
`json:"image_id";orm:"column(image_id)"`
ImageUrl
string
`json:"image_url";orm:"column(image_url)"`
ImageUrl
string
`json:"image_url";orm:"column(image_url)"`
...
@@ -34,6 +50,12 @@ type TaskType struct {
...
@@ -34,6 +50,12 @@ type TaskType struct {
SignUrl
string
`json:"sign_url";orm:"column(sign_url)"`
SignUrl
string
`json:"sign_url";orm:"column(sign_url)"`
Username
string
`json:"username";orm:"column(username)"`
Username
string
`json:"username";orm:"column(username)"`
Password
string
`json:"password";orm:"column(password)"`
Password
string
`json:"password";orm:"column(password)"`
BaseModel
string
`json:"base_model";orm:"column(base_model)"`
Examples
string
`json:"examples";orm:"column(examples)"`
ApiDocUrl
string
`json:"api_doc_url";orm:"column(api_doc_url)"`
ApiDocContent
string
`json:"api_doc_content";orm:"column(api_doc_content)"`
Codes
string
`json:"codes";orm:"column(codes)"`
Tags
string
`json:"tags";orm:"column(tags)"`
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)"`
Deleted
int
`json:"deleted";orm:"column(deleted);size(1)"`
Deleted
int
`json:"deleted";orm:"column(deleted);size(1)"`
...
@@ -41,25 +63,67 @@ type TaskType struct {
...
@@ -41,25 +63,67 @@ type TaskType struct {
type
NewTaskType
struct
{
type
NewTaskType
struct
{
Id
int
`orm:"column(id);auto"`
Id
int
`orm:"column(id);auto"`
Name
string
`json:"name";orm:"column(desc)"`
BaseModel
string
`json:"base_model";orm:"column(desc)"`
Version
string
`json:"version";orm:"column(desc)"`
Desc
string
`json:"desc";orm:"column(desc);size(20)"`
Desc
string
`json:"desc";orm:"column(desc);size(20)"`
Price
int64
`json:"price";orm:"column(price)"`
Price
float64
`json:"price";orm:"column(price)"`
PublicKey
string
`json:"public_key";orm:"column(public_key)"`
PublicKey
string
`json:"public_key";orm:"column(public_key)"`
Complexity
int
`json:"complexity";orm:"column(complexity)"`
Complexity
int
`json:"complexity";orm:"column(complexity)"`
HardwareRequire
Hardware
`json:"hardware_require";orm:"column(hardware_require)"`
Type
ModelType
`json:"type,omitempty";orm:"column(type)"`
Kind
int
`json:"kind";orm:"column(kind)"`
TypeDesc
string
`json:"type_desc"`
KindDesc
string
`json:"kind_desc"`
HardwareRequire
interface
{}
`json:"hardware_require";orm:"column(hardware_require)"`
ImageId
string
`json:"image_id";orm:"column(image_id)"`
ImageId
string
`json:"image_id";orm:"column(image_id)"`
ImageUrl
string
`json:"image_url";orm:"column(image_url)"`
ImageUrl
string
`json:"image_url";orm:"column(image_url)"`
Cmd
CMD
`json:"cmd";orm:"column(cmd)"`
Cmd
interface
{}
`json:"cmd";orm:"column(cmd)"`
Workload
int
`json:"workload";orm:"column(workload)"`
Workload
int
`json:"workload";orm:"column(workload)"`
ApiPath
string
`json:"api_path";orm:"column(api_path)"`
ApiPath
string
`json:"api_path";orm:"column(api_path)"`
ImageName
string
`json:"image_name";orm:"column(image_name)"`
ImageName
string
`json:"image_name";orm:"column(image_name)"`
SignUrl
string
`json:"sign_url";orm:"column(sign_url)"`
SignUrl
string
`json:"sign_url";orm:"column(sign_url)"`
Username
string
`json:"username";orm:"column(username)"`
Username
string
`json:"username";orm:"column(username)"`
Password
string
`json:"password";orm:"column(password)"`
Password
string
`json:"password";orm:"column(password)"`
Examples
[]
ExampleType
`json:"examples,omitempty";orm:"column(examples)"`
ApiDocUrl
string
`json:"api_doc_url,omitempty";orm:"column(api_doc_url)"`
ApiDocContent
string
`json:"api_doc_content,omitempty";orm:"column(api_doc_content)"`
Codes
interface
{}
`json:"codes,omitempty";orm:"column(codes)"`
Tags
[]
string
`json:"tags,omitempty";orm:"column(tags)"`
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)"`
Deleted
int
`json:"deleted";orm:"column(deleted);size(1)"`
Deleted
int
`json:"deleted";orm:"column(deleted);size(1)"`
}
}
type
Model
struct
{
Id
int
`orm:"column(id);auto"`
Tit
string
`json:"tit";orm:"column(tit);size(20)"`
Version
string
`json:"version,omitempty";orm:"column(version)"`
Content
string
`json:"content";orm:"column(content);size(20)"`
Type
int
`json:"type";orm:"column(type)"`
ApiPath
string
`json:"api_path";orm:"column(api_path)"`
BaseModel
string
`json:"base_model";orm:"column(base_model)"`
Examples
string
`json:"examples";orm:"column(examples)"`
ApiDocUrl
string
`json:"api_doc_url";orm:"column(api_doc_url)"`
ApiDocContent
string
`json:"api_doc_content";orm:"column(api_doc_content)"`
Codes
string
`json:"codes";orm:"column(codes)"`
Tags
string
`json:"tags";orm:"column(tags)"`
}
type
ResonseModel
struct
{
Id
int
`json:"id";orm:"column(id)"`
Tit
string
`json:"tit";orm:"column(tit);size(20)"`
Version
string
`json:"version,omitempty";orm:"column(version)"`
Content
string
`json:"content";orm:"column(content);size(20)"`
Type
int
`json:"type";orm:"column(type)"`
ApiPath
string
`json:"api_path";orm:"column(api_path)"`
BaseModel
string
`json:"base_model";orm:"column(base_model)"`
Examples
interface
{}
`json:"examples";orm:"column(examples)"`
ApiDocUrl
string
`json:"api_doc_url,omitempty";orm:"column(api_doc_url)"`
ApiDocContent
string
`json:"api_doc_content,omitempty";orm:"column(api_doc_content)"`
Codes
interface
{}
`json:"codes";orm:"column(codes)"`
Tags
interface
{}
`json:"tags";orm:"column(tags)"`
}
type
Bills
struct
{
type
Bills
struct
{
//Key int `orm:"column(key);auto"`
//Key int `orm:"column(key);auto"`
Id
string
`json:"id";orm:"column(id)"`
Id
string
`json:"id";orm:"column(id)"`
...
@@ -101,7 +165,7 @@ type TaskHeat struct {
...
@@ -101,7 +165,7 @@ type TaskHeat struct {
Time
time
.
Time
`json:"time,omitempty"`
Time
time
.
Time
`json:"time,omitempty"`
Count
int64
`json:"count,omitempty"`
Count
int64
`json:"count,omitempty"`
ApiPath
string
`json:"api_path,omitempty"`
ApiPath
string
`json:"api_path,omitempty"`
HardwareRequire
Hardware
`json:"hardware_require,omitempty"`
HardwareRequire
interface
{}
`json:"hardware_require,omitempty"`
ImageId
string
`json:"image_id,omitempty"`
ImageId
string
`json:"image_id,omitempty"`
Repository
string
`json:"repository,omitempty"`
Repository
string
`json:"repository,omitempty"`
ImageName
string
`json:"image_name,omitempty"`
ImageName
string
`json:"image_name,omitempty"`
...
@@ -109,6 +173,7 @@ type TaskHeat struct {
...
@@ -109,6 +173,7 @@ type TaskHeat struct {
User
string
`json:"user,omitempty"`
User
string
`json:"user,omitempty"`
Pwd
string
`json:"pwd,omitempty"`
Pwd
string
`json:"pwd,omitempty"`
TaskId
int
`json:"task_id,omitempty"`
TaskId
int
`json:"task_id,omitempty"`
Kind
int
`json:"kind";orm:"column(kind)"`
}
}
//type Tasks struct {
//type Tasks struct {
...
@@ -123,6 +188,51 @@ type TaskHeat struct {
...
@@ -123,6 +188,51 @@ type TaskHeat struct {
//}
//}
type
AddTaskType
struct
{
type
AddTaskType
struct
{
T
ype
NewTaskType
`json:"
type"`
T
askTypeIn
NewTaskType
`json:"task_
type"`
Levels
[]
UserLevelTaskType
`json:"levels"`
Levels
[]
UserLevelTaskType
`json:"levels"`
}
}
type
ModelType
int
const
(
TXTTOIMG
ModelType
=
iota
+
1
TXTTOTXT
TXTTOVIDEO
)
func
(
m
ModelType
)
String
()
string
{
switch
m
{
case
TXTTOIMG
:
return
"txt2img"
case
TXTTOTXT
:
return
"txt2txt"
case
TXTTOVIDEO
:
return
"txt2video"
default
:
return
"未知类型"
}
}
type
TaskKind
int
const
(
SystemTask
TaskKind
=
iota
ComputeTask
=
1
CustomTask
=
2
StandardTask
=
3
)
func
(
m
TaskKind
)
String
()
string
{
switch
m
{
case
SystemTask
:
return
"系统任务"
case
ComputeTask
:
return
"计算任务"
case
CustomTask
:
return
"自定义任务"
case
StandardTask
:
return
"标准任务"
default
:
return
"未知类型"
}
}
models/user.go
View file @
18776250
...
@@ -60,7 +60,7 @@ type UserLevel struct {
...
@@ -60,7 +60,7 @@ type UserLevel struct {
}
}
type
UserLevelTaskType
struct
{
type
UserLevelTaskType
struct
{
I
D
int
`orm:"column(id);auto"`
I
d
int
`orm:"column(id);auto"`
FreeCallCountDay
int
`json:"free_call_count_day"orm:"column(free_call_count_day)"`
FreeCallCountDay
int
`json:"free_call_count_day"orm:"column(free_call_count_day)"`
FreeCallCountMonth
int
`json:"free_call_count_month"orm:"column(free_call_count_month)"`
FreeCallCountMonth
int
`json:"free_call_count_month"orm:"column(free_call_count_month)"`
FreeCallCountYear
int
`json:"free_call_count_year"orm:"column(free_call_count_year)"`
FreeCallCountYear
int
`json:"free_call_count_year"orm:"column(free_call_count_year)"`
...
...
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