From b4f2157f057d95c84ec3bc26e4cdfc77b301ee06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 29 Nov 2024 11:07:41 +0100 Subject: [PATCH] log when asset already exists in DB (#234885) --- build/azure-pipelines/common/publish.js | 14 ++++++++++---- build/azure-pipelines/common/publish.ts | 13 +++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/build/azure-pipelines/common/publish.js b/build/azure-pipelines/common/publish.js index 3816db385a0..102c5518d9b 100644 --- a/build/azure-pipelines/common/publish.js +++ b/build/azure-pipelines/common/publish.js @@ -500,14 +500,20 @@ async function processArtifact(artifact, filePath) { await releaseService.createRelease(version, filePath, friendlyFileName); } const asset = { platform, type, url, hash: hash.toString('hex'), sha256hash: sha256hash.toString('hex'), size, supportsFastUpdate: true }; - log('Creating asset...', JSON.stringify(asset, undefined, 2)); - await (0, retry_1.retry)(async (attempt) => { + log('Creating asset...'); + const result = await (0, retry_1.retry)(async (attempt) => { log(`Creating asset in Cosmos DB (attempt ${attempt})...`); const client = new cosmos_1.CosmosClient({ endpoint: e('AZURE_DOCUMENTDB_ENDPOINT'), tokenProvider: () => Promise.resolve(`type=aad&ver=1.0&sig=${cosmosDBAccessToken.token}`) }); const scripts = client.database('builds').container(quality).scripts; - await scripts.storedProcedure('createAsset').execute('', [version, asset, true]); + const { resource: result } = await scripts.storedProcedure('createAsset').execute('', [version, asset, true]); + return result; }); - log('Asset successfully created'); + if (result === 'already exists') { + log('Asset already exists!'); + } + else { + log('Asset successfully created: ', JSON.stringify(asset, undefined, 2)); + } } // It is VERY important that we don't download artifacts too much too fast from AZDO. // AZDO throttles us SEVERELY if we do. Not just that, but they also close open diff --git a/build/azure-pipelines/common/publish.ts b/build/azure-pipelines/common/publish.ts index a3760c03434..ab9270e177d 100644 --- a/build/azure-pipelines/common/publish.ts +++ b/build/azure-pipelines/common/publish.ts @@ -834,16 +834,21 @@ async function processArtifact( } const asset: Asset = { platform, type, url, hash: hash.toString('hex'), sha256hash: sha256hash.toString('hex'), size, supportsFastUpdate: true }; - log('Creating asset...', JSON.stringify(asset, undefined, 2)); + log('Creating asset...'); - await retry(async (attempt) => { + const result = await retry(async (attempt) => { log(`Creating asset in Cosmos DB (attempt ${attempt})...`); const client = new CosmosClient({ endpoint: e('AZURE_DOCUMENTDB_ENDPOINT')!, tokenProvider: () => Promise.resolve(`type=aad&ver=1.0&sig=${cosmosDBAccessToken.token}`) }); const scripts = client.database('builds').container(quality).scripts; - await scripts.storedProcedure('createAsset').execute('', [version, asset, true]); + const { resource: result } = await scripts.storedProcedure('createAsset').execute<'ok' | 'already exists'>('', [version, asset, true]); + return result; }); - log('Asset successfully created'); + if (result === 'already exists') { + log('Asset already exists!'); + } else { + log('Asset successfully created: ', JSON.stringify(asset, undefined, 2)); + } } // It is VERY important that we don't download artifacts too much too fast from AZDO.