Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
7a38a81e
authored
Jun 06, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: task and inform
parent
55d0ed9d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
42 deletions
+87
-42
src/hooks/usePagination.tsx
+1
-1
src/pages/api/user/checkPayResult.ts
+19
-1
src/pages/api/user/inform/send.ts
+36
-22
src/pages/number/components/PayModal.tsx
+1
-0
src/service/events/generateQA.ts
+15
-3
src/service/events/generateVector.ts
+15
-3
src/service/mongo.ts
+0
-12
No files found.
src/hooks/usePagination.tsx
View file @
7a38a81e
...
@@ -31,7 +31,7 @@ export const usePagination = <T = any,>({
...
@@ -31,7 +31,7 @@ export const usePagination = <T = any,>({
...
params
...
params
});
});
setPageNum
(
num
);
setPageNum
(
num
);
res
.
total
&&
setTotal
(
res
.
total
);
res
.
total
!==
undefined
&&
setTotal
(
res
.
total
);
setData
(
res
.
data
);
setData
(
res
.
data
);
}
catch
(
error
:
any
)
{
}
catch
(
error
:
any
)
{
toast
({
toast
({
...
...
src/pages/api/user/checkPayResult.ts
View file @
7a38a81e
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
User
,
Pay
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
User
,
Pay
,
TrainingData
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
PaySchema
,
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
{
PaySchema
,
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
dayjs
from
'dayjs'
;
import
dayjs
from
'dayjs'
;
import
{
getPayResult
}
from
'@/service/utils/wxpay'
;
import
{
getPayResult
}
from
'@/service/utils/wxpay'
;
import
{
pushPromotionRecord
}
from
'@/service/utils/promotion'
;
import
{
pushPromotionRecord
}
from
'@/service/utils/promotion'
;
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
import
{
startQueue
}
from
'@/service/utils/tools'
;
/* 校验支付结果 */
/* 校验支付结果 */
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
...
@@ -75,6 +76,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -75,6 +76,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
jsonRes
(
res
,
{
jsonRes
(
res
,
{
data
:
'支付成功'
data
:
'支付成功'
});
});
unlockTask
(
userId
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
await
Pay
.
findByIdAndUpdate
(
payId
,
{
await
Pay
.
findByIdAndUpdate
(
payId
,
{
...
@@ -101,3 +103,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -101,3 +103,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
});
}
}
}
}
async
function
unlockTask
(
userId
:
string
)
{
try
{
await
TrainingData
.
updateMany
(
{
userId
},
{
lockTime
:
new
Date
(
'2000/1/1'
)
}
);
startQueue
();
}
catch
(
error
)
{
unlockTask
(
userId
);
}
}
src/pages/api/user/inform/send.ts
View file @
7a38a81e
...
@@ -32,30 +32,44 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -32,30 +32,44 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
export
async
function
sendInform
({
type
,
title
,
content
,
userId
}:
Props
)
{
export
async
function
sendInform
({
type
,
title
,
content
,
userId
}:
Props
)
{
if
(
!
type
||
!
title
||
!
content
)
{
if
(
!
type
||
!
title
||
!
content
)
{
return
Promise
.
reject
(
'参数错误'
)
;
return
;
}
}
if
(
userId
)
{
try
{
await
Inform
.
create
({
if
(
userId
)
{
type
,
// skip it if have same inform within 5 minutes
title
,
const
inform
=
await
Inform
.
findOne
({
content
,
type
,
userId
title
,
});
content
,
userId
,
read
:
false
,
time
:
{
$lte
:
new
Date
(
Date
.
now
()
+
5
*
60
*
1000
)
}
});
return
;
if
(
inform
)
return
;
}
await
Inform
.
create
({
type
,
title
,
content
,
userId
});
// send to all user
return
;
const
users
=
await
User
.
find
({},
'_id'
);
}
await
Inform
.
insertMany
(
users
.
map
(({
_id
})
=>
({
// send to all user
type
,
const
users
=
await
User
.
find
({},
'_id'
);
title
,
await
Inform
.
insertMany
(
content
,
users
.
map
(({
_id
})
=>
({
userId
:
_id
type
,
}))
title
,
);
content
,
userId
:
_id
return
;
}))
);
}
catch
(
error
)
{
console
.
log
(
'send inform error'
,
error
);
}
}
}
src/pages/number/components/PayModal.tsx
View file @
7a38a81e
...
@@ -57,6 +57,7 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -57,6 +57,7 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
return
checkPayResult
(
payId
);
return
checkPayResult
(
payId
);
},
},
{
{
enabled
:
!!
payId
,
refetchInterval
:
2000
,
refetchInterval
:
2000
,
onSuccess
(
res
)
{
onSuccess
(
res
)
{
if
(
!
res
)
return
;
if
(
!
res
)
return
;
...
...
src/service/events/generateQA.ts
View file @
7a38a81e
...
@@ -9,6 +9,7 @@ import { BillTypeEnum } from '@/constants/user';
...
@@ -9,6 +9,7 @@ import { BillTypeEnum } from '@/constants/user';
import
{
pushDataToKb
}
from
'@/pages/api/openapi/kb/pushData'
;
import
{
pushDataToKb
}
from
'@/pages/api/openapi/kb/pushData'
;
import
{
TrainingModeEnum
}
from
'@/constants/plugin'
;
import
{
TrainingModeEnum
}
from
'@/constants/plugin'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
sendInform
}
from
'@/pages/api/user/inform/send'
;
const
reduceQueue
=
()
=>
{
const
reduceQueue
=
()
=>
{
global
.
qaQueueLen
=
global
.
qaQueueLen
>
0
?
global
.
qaQueueLen
-
1
:
0
;
global
.
qaQueueLen
=
global
.
qaQueueLen
>
0
?
global
.
qaQueueLen
-
1
:
0
;
...
@@ -174,11 +175,22 @@ A2:
...
@@ -174,11 +175,22 @@ A2:
}
}
// 账号余额不足,删除任务
// 账号余额不足,删除任务
if
(
err
===
ERROR_ENUM
.
insufficientQuota
)
{
if
(
userId
&&
err
===
ERROR_ENUM
.
insufficientQuota
)
{
console
.
log
(
'余额不足,删除向量生成任务'
);
sendInform
({
await
TrainingData
.
deleteMany
({
type
:
'system'
,
title
:
'QA 任务中止'
,
content
:
'由于账号余额不足,QA 任务中止,重新充值后将会继续。'
,
userId
userId
});
});
console
.
log
(
'余额不足,暂停向量生成任务'
);
await
TrainingData
.
updateMany
(
{
userId
},
{
lockTime
:
new
Date
(
'2999/5/5'
)
}
);
return
generateQA
();
return
generateQA
();
}
}
...
...
src/service/events/generateVector.ts
View file @
7a38a81e
...
@@ -4,6 +4,7 @@ import { openaiEmbedding } from '@/pages/api/openapi/plugin/openaiEmbedding';
...
@@ -4,6 +4,7 @@ import { openaiEmbedding } from '@/pages/api/openapi/plugin/openaiEmbedding';
import
{
TrainingData
}
from
'../models/trainingData'
;
import
{
TrainingData
}
from
'../models/trainingData'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
TrainingModeEnum
}
from
'@/constants/plugin'
;
import
{
TrainingModeEnum
}
from
'@/constants/plugin'
;
import
{
sendInform
}
from
'@/pages/api/user/inform/send'
;
const
reduceQueue
=
()
=>
{
const
reduceQueue
=
()
=>
{
global
.
vectorQueueLen
=
global
.
vectorQueueLen
>
0
?
global
.
vectorQueueLen
-
1
:
0
;
global
.
vectorQueueLen
=
global
.
vectorQueueLen
>
0
?
global
.
vectorQueueLen
-
1
:
0
;
...
@@ -125,11 +126,22 @@ export async function generateVector(): Promise<any> {
...
@@ -125,11 +126,22 @@ export async function generateVector(): Promise<any> {
}
}
// 账号余额不足,删除任务
// 账号余额不足,删除任务
if
(
err
===
ERROR_ENUM
.
insufficientQuota
)
{
if
(
userId
&&
err
===
ERROR_ENUM
.
insufficientQuota
)
{
console
.
log
(
'余额不足,删除向量生成任务'
);
sendInform
({
await
TrainingData
.
deleteMany
({
type
:
'system'
,
title
:
'索引生成任务中止'
,
content
:
'由于账号余额不足,索引生成任务中止,重新充值后将会继续。'
,
userId
userId
});
});
console
.
log
(
'余额不足,暂停向量生成任务'
);
await
TrainingData
.
updateMany
(
{
userId
},
{
lockTime
:
new
Date
(
'2999/5/5'
)
}
);
return
generateVector
();
return
generateVector
();
}
}
...
...
src/service/mongo.ts
View file @
7a38a81e
...
@@ -42,18 +42,6 @@ export async function connectToDatabase(): Promise<void> {
...
@@ -42,18 +42,6 @@ export async function connectToDatabase(): Promise<void> {
global
.
vectorQueueLen
=
0
;
global
.
vectorQueueLen
=
0
;
startQueue
();
startQueue
();
// 5 分钟后解锁不正常的数据,并触发开始训练
setTimeout
(
async
()
=>
{
await
TrainingData
.
updateMany
(
{
lockTime
:
{
$lte
:
Date
.
now
()
-
5
*
60
*
1000
}
},
{
lockTime
:
new
Date
(
'2000/1/1'
)
}
);
startQueue
();
},
5
*
60
*
1000
);
}
}
export
*
from
'./models/authCode'
;
export
*
from
'./models/authCode'
;
...
...
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