uberf-8294: do not upgrade stale workspaces (#6748)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-09-26 18:47:36 +04:00 committed by GitHub
parent 3c63f108b2
commit b585a9a721
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1017,7 +1017,8 @@ export async function listWorkspacesByAccount (db: Db, email: string): Promise<W
export async function countWorkspacesInRegion (
db: Db,
region: string = '',
upToVersion?: Data<Version>
upToVersion?: Data<Version>,
visitedSince?: number
): Promise<number> {
const regionQuery = region === '' ? { $or: [{ region: { $exists: false } }, { region: '' }] } : { region }
const query: Filter<Workspace>['$and'] = [
@ -1039,6 +1040,10 @@ export async function countWorkspacesInRegion (
})
}
if (visitedSince !== undefined) {
query.push({ lastVisit: { $gt: visitedSince } })
}
return await db.collection<Workspace>(WORKSPACE_COLLECTION).countDocuments({
$and: query
})
@ -1256,7 +1261,7 @@ export async function workerHandshake (
const workspacesCnt = await ctx.with(
'count-workspaces-in-region',
{},
async (ctx) => await countWorkspacesInRegion(db, region, version)
async (ctx) => await countWorkspacesInRegion(db, region, version, Date.now() - 24 * 60 * 60 * 1000)
)
await db.collection<UpgradeStatistic>(UPGRADE_COLLECTION).insertOne({
@ -1494,7 +1499,10 @@ export async function getPendingWorkspace (
{
$or: [{ mode: 'active' }, { mode: { $exists: false } }]
},
versionQuery
versionQuery,
{
lastVisit: { $gt: Date.now() - 24 * 60 * 60 * 1000 }
}
]
},
{