UBERF-9496 (#8061)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2025-02-20 22:28:59 +07:00
committed by GitHub
parent 9e202352eb
commit 3cc324da77
8 changed files with 114 additions and 131 deletions
+19 -13
View File
@@ -11,6 +11,7 @@ import core, {
ClientConnectEvent,
DocumentUpdate,
isActiveMode,
isDeletingMode,
MeasureContext,
RateLimiter,
Ref,
@@ -712,33 +713,36 @@ export class PlatformWorker {
return Array.from(workspaces)
}
async checkWorkspaceIsActive (token: string, workspace: string): Promise<ClientWorkspaceInfo | undefined> {
async checkWorkspaceIsActive (
token: string,
workspace: string
): Promise<{ workspaceInfo: ClientWorkspaceInfo | undefined, needRecheck: boolean }> {
let workspaceInfo: ClientWorkspaceInfo | undefined
try {
workspaceInfo = await getWorkspaceInfo(token)
} catch (err: any) {
this.ctx.error('Workspace not found:', { workspace })
return
return { workspaceInfo: undefined, needRecheck: false }
}
if (workspaceInfo?.workspace === undefined) {
this.ctx.error('No workspace exists for workspaceId', { workspace })
return
return { workspaceInfo: undefined, needRecheck: false }
}
if (workspaceInfo?.disabled === true || isDeletingMode(workspaceInfo?.mode)) {
this.ctx.warn('Workspace is disabled', { workspace })
return { workspaceInfo: undefined, needRecheck: false }
}
if (!isActiveMode(workspaceInfo?.mode)) {
this.ctx.warn('Workspace is in maitenance, skipping for now.', { workspace })
return
}
if (workspaceInfo?.disabled === true) {
this.ctx.warn('Workspace is disabled', { workspace })
return
this.ctx.warn('Workspace is in maitenance, skipping for now.', { workspace, mode: workspaceInfo?.mode })
return { workspaceInfo: undefined, needRecheck: true }
}
const lastVisit = (Date.now() - workspaceInfo.lastVisit) / (3600 * 24 * 1000) // In days
if (config.WorkspaceInactivityInterval > 0 && lastVisit > config.WorkspaceInactivityInterval) {
this.ctx.warn('Workspace is inactive for too long, skipping for now.', { workspace })
return
return { workspaceInfo: undefined, needRecheck: true }
}
return workspaceInfo
return { workspaceInfo, needRecheck: true }
}
private async checkWorkspaces (): Promise<boolean> {
@@ -781,9 +785,11 @@ export class PlatformWorker {
},
{ mode: 'github' }
)
const workspaceInfo = await this.checkWorkspaceIsActive(token, workspace)
const { workspaceInfo, needRecheck } = await this.checkWorkspaceIsActive(token, workspace)
if (workspaceInfo === undefined) {
errors++
if (needRecheck) {
errors++
}
return
}
try {