mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 03:14:40 +03:00
uberf-8480: configurable liveness condition for upgrade (#6943)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
6b112fc1be
commit
171e1e88b7
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
@ -95,6 +95,7 @@
|
|||||||
"ACCOUNT_PORT": "3000",
|
"ACCOUNT_PORT": "3000",
|
||||||
"FRONT_URL": "http://localhost:8080",
|
"FRONT_URL": "http://localhost:8080",
|
||||||
"SES_URL": "",
|
"SES_URL": "",
|
||||||
|
// "WS_LIVENESS_DAYS": "1",
|
||||||
"MINIO_ACCESS_KEY": "minioadmin",
|
"MINIO_ACCESS_KEY": "minioadmin",
|
||||||
"MINIO_SECRET_KEY": "minioadmin",
|
"MINIO_SECRET_KEY": "minioadmin",
|
||||||
"MINIO_ENDPOINT": "localhost",
|
"MINIO_ENDPOINT": "localhost",
|
||||||
|
@ -83,6 +83,7 @@ services:
|
|||||||
- RESERVED_DB_NAMES=telegram,gmail,github
|
- RESERVED_DB_NAMES=telegram,gmail,github
|
||||||
- MODEL_ENABLED=*
|
- MODEL_ENABLED=*
|
||||||
- LAST_NAME_FIRST=true
|
- LAST_NAME_FIRST=true
|
||||||
|
# - WS_LIVENESS_DAYS=1
|
||||||
- ACCOUNTS_URL=http://host.docker.internal:3000
|
- ACCOUNTS_URL=http://host.docker.internal:3000
|
||||||
- BRANDING_PATH=/var/cfg/branding.json
|
- BRANDING_PATH=/var/cfg/branding.json
|
||||||
# - DISABLE_SIGNUP=true
|
# - DISABLE_SIGNUP=true
|
||||||
|
@ -65,6 +65,17 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
|
|||||||
const productName = process.env.PRODUCT_NAME
|
const productName = process.env.PRODUCT_NAME
|
||||||
const lang = process.env.LANGUAGE ?? 'en'
|
const lang = process.env.LANGUAGE ?? 'en'
|
||||||
|
|
||||||
|
const wsLivenessDaysRaw = process.env.WS_LIVENESS_DAYS
|
||||||
|
let wsLivenessDays: number | undefined
|
||||||
|
|
||||||
|
if (wsLivenessDaysRaw !== undefined) {
|
||||||
|
try {
|
||||||
|
wsLivenessDays = parseInt(wsLivenessDaysRaw)
|
||||||
|
} catch (err: any) {
|
||||||
|
// DO NOTHING
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setMetadata(account.metadata.Transactors, transactorUri)
|
setMetadata(account.metadata.Transactors, transactorUri)
|
||||||
setMetadata(platform.metadata.locale, lang)
|
setMetadata(platform.metadata.locale, lang)
|
||||||
setMetadata(account.metadata.ProductName, productName)
|
setMetadata(account.metadata.ProductName, productName)
|
||||||
@ -72,6 +83,7 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
|
|||||||
setMetadata(account.metadata.OtpRetryDelaySec, parseInt(process.env.OTP_RETRY_DELAY ?? '60'))
|
setMetadata(account.metadata.OtpRetryDelaySec, parseInt(process.env.OTP_RETRY_DELAY ?? '60'))
|
||||||
setMetadata(account.metadata.SES_URL, ses)
|
setMetadata(account.metadata.SES_URL, ses)
|
||||||
setMetadata(account.metadata.FrontURL, frontURL)
|
setMetadata(account.metadata.FrontURL, frontURL)
|
||||||
|
setMetadata(account.metadata.WsLivenessDays, wsLivenessDays)
|
||||||
|
|
||||||
setMetadata(serverToken.metadata.Secret, serverSecret)
|
setMetadata(serverToken.metadata.Secret, serverSecret)
|
||||||
|
|
||||||
|
@ -212,7 +212,8 @@ export class WorkspaceMongoDbCollection extends MongoDbCollection<Workspace> imp
|
|||||||
region: string,
|
region: string,
|
||||||
version: Data<Version>,
|
version: Data<Version>,
|
||||||
operation: WorkspaceOperation,
|
operation: WorkspaceOperation,
|
||||||
processingTimeoutMs: number
|
processingTimeoutMs: number,
|
||||||
|
wsLivenessMs?: number
|
||||||
): Promise<WorkspaceInfo | undefined> {
|
): Promise<WorkspaceInfo | undefined> {
|
||||||
const pendingCreationQuery: Filter<Workspace>['$or'] = [{ mode: { $in: ['pending-creation', 'creating'] } }]
|
const pendingCreationQuery: Filter<Workspace>['$or'] = [{ mode: { $in: ['pending-creation', 'creating'] } }]
|
||||||
|
|
||||||
@ -233,9 +234,13 @@ export class WorkspaceMongoDbCollection extends MongoDbCollection<Workspace> imp
|
|||||||
$or: [{ mode: 'active' }, { mode: { $exists: false } }]
|
$or: [{ mode: 'active' }, { mode: { $exists: false } }]
|
||||||
},
|
},
|
||||||
versionQuery,
|
versionQuery,
|
||||||
{
|
...(wsLivenessMs !== undefined
|
||||||
lastVisit: { $gt: Date.now() - 24 * 60 * 60 * 1000 }
|
? [
|
||||||
}
|
{
|
||||||
|
lastVisit: { $gt: Date.now() - wsLivenessMs }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
: [])
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -358,7 +358,8 @@ export class WorkspacePostgresDbCollection extends PostgresDbCollection<Workspac
|
|||||||
region: string,
|
region: string,
|
||||||
version: Data<Version>,
|
version: Data<Version>,
|
||||||
operation: WorkspaceOperation,
|
operation: WorkspaceOperation,
|
||||||
processingTimeoutMs: number
|
processingTimeoutMs: number,
|
||||||
|
wsLivenessMs?: number
|
||||||
): Promise<WorkspaceInfo | undefined> {
|
): Promise<WorkspaceInfo | undefined> {
|
||||||
const sqlChunks: string[] = [`SELECT * FROM ${this.name}`]
|
const sqlChunks: string[] = [`SELECT * FROM ${this.name}`]
|
||||||
const whereChunks: string[] = []
|
const whereChunks: string[] = []
|
||||||
@ -367,7 +368,7 @@ export class WorkspacePostgresDbCollection extends PostgresDbCollection<Workspac
|
|||||||
const pendingCreationSql = "mode IN ('pending-creation', 'creating')"
|
const pendingCreationSql = "mode IN ('pending-creation', 'creating')"
|
||||||
const versionSql =
|
const versionSql =
|
||||||
'("versionMajor" < $1) OR ("versionMajor" = $1 AND "versionMinor" < $2) OR ("versionMajor" = $1 AND "versionMinor" = $2 AND "versionPatch" < $3)'
|
'("versionMajor" < $1) OR ("versionMajor" = $1 AND "versionMinor" < $2) OR ("versionMajor" = $1 AND "versionMinor" = $2 AND "versionPatch" < $3)'
|
||||||
const pendingUpgradeSql = `(((disabled = FALSE OR disabled IS NULL) AND (mode = 'active' OR mode IS NULL) AND ${versionSql} AND "lastVisit" > $4) OR ((disabled = FALSE OR disabled IS NULL) AND mode = 'upgrading'))`
|
const pendingUpgradeSql = `(((disabled = FALSE OR disabled IS NULL) AND (mode = 'active' OR mode IS NULL) AND ${versionSql} ${wsLivenessMs !== undefined ? 'AND "lastVisit" > $4' : ''}) OR ((disabled = FALSE OR disabled IS NULL) AND mode = 'upgrading'))`
|
||||||
const operationSql =
|
const operationSql =
|
||||||
operation === 'create'
|
operation === 'create'
|
||||||
? pendingCreationSql
|
? pendingCreationSql
|
||||||
@ -375,7 +376,11 @@ export class WorkspacePostgresDbCollection extends PostgresDbCollection<Workspac
|
|||||||
? pendingUpgradeSql
|
? pendingUpgradeSql
|
||||||
: `(${pendingCreationSql} OR ${pendingUpgradeSql})`
|
: `(${pendingCreationSql} OR ${pendingUpgradeSql})`
|
||||||
if (operation === 'upgrade' || operation === 'all') {
|
if (operation === 'upgrade' || operation === 'all') {
|
||||||
values.push(version.major, version.minor, version.patch, Date.now() - 24 * 60 * 60 * 1000)
|
values.push(version.major, version.minor, version.patch)
|
||||||
|
|
||||||
|
if (wsLivenessMs !== undefined) {
|
||||||
|
values.push(Date.now() - wsLivenessMs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
whereChunks.push(operationSql)
|
whereChunks.push(operationSql)
|
||||||
|
|
||||||
@ -383,11 +388,11 @@ export class WorkspacePostgresDbCollection extends PostgresDbCollection<Workspac
|
|||||||
// to clear them with the worker.
|
// to clear them with the worker.
|
||||||
|
|
||||||
whereChunks.push('(attempts IS NULL OR attempts <= 3)')
|
whereChunks.push('(attempts IS NULL OR attempts <= 3)')
|
||||||
whereChunks.push('("lastProcessingTime" IS NULL OR "lastProcessingTime" < $5)')
|
whereChunks.push(`("lastProcessingTime" IS NULL OR "lastProcessingTime" < $${values.length + 1})`)
|
||||||
values.push(Date.now() - processingTimeoutMs)
|
values.push(Date.now() - processingTimeoutMs)
|
||||||
|
|
||||||
if (region !== '') {
|
if (region !== '') {
|
||||||
whereChunks.push('region = $6')
|
whereChunks.push(`region = $${values.length + 1}`)
|
||||||
values.push(region)
|
values.push(region)
|
||||||
} else {
|
} else {
|
||||||
whereChunks.push("(region IS NULL OR region = '')")
|
whereChunks.push("(region IS NULL OR region = '')")
|
||||||
|
@ -1278,8 +1278,10 @@ export async function getPendingWorkspace (
|
|||||||
}
|
}
|
||||||
// Move to config?
|
// Move to config?
|
||||||
const processingTimeoutMs = 30 * 1000
|
const processingTimeoutMs = 30 * 1000
|
||||||
|
const wsLivenessDays = getMetadata(accountPlugin.metadata.WsLivenessDays)
|
||||||
|
const wsLivenessMs = wsLivenessDays !== undefined ? wsLivenessDays * 24 * 60 * 60 * 1000 : undefined
|
||||||
|
|
||||||
const result = await db.workspace.getPendingWorkspace(region, version, operation, processingTimeoutMs)
|
const result = await db.workspace.getPendingWorkspace(region, version, operation, processingTimeoutMs, wsLivenessMs)
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
ctx.info('getPendingWorkspace', {
|
ctx.info('getPendingWorkspace', {
|
||||||
|
@ -15,7 +15,8 @@ export const accountPlugin = plugin(accountId, {
|
|||||||
ProductName: '' as Metadata<string>,
|
ProductName: '' as Metadata<string>,
|
||||||
Transactors: '' as Metadata<string>,
|
Transactors: '' as Metadata<string>,
|
||||||
OtpTimeToLiveSec: '' as Metadata<number>,
|
OtpTimeToLiveSec: '' as Metadata<number>,
|
||||||
OtpRetryDelaySec: '' as Metadata<number>
|
OtpRetryDelaySec: '' as Metadata<number>,
|
||||||
|
WsLivenessDays: '' as Metadata<number>
|
||||||
},
|
},
|
||||||
string: {
|
string: {
|
||||||
ConfirmationText: '' as IntlString,
|
ConfirmationText: '' as IntlString,
|
||||||
|
@ -195,6 +195,7 @@ export interface WorkspaceDbCollection extends DbCollection<Workspace> {
|
|||||||
region: string,
|
region: string,
|
||||||
version: Data<Version>,
|
version: Data<Version>,
|
||||||
operation: WorkspaceOperation,
|
operation: WorkspaceOperation,
|
||||||
processingTimeoutMs: number
|
processingTimeoutMs: number,
|
||||||
|
wsLivenessMs?: number
|
||||||
) => Promise<WorkspaceInfo | undefined>
|
) => Promise<WorkspaceInfo | undefined>
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user