mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-28 18:59:50 +02:00
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user