From c992041d16ec10d790e6204dce9abf9966d1363c Mon Sep 17 00:00:00 2001 From: Deepankar Bajpeyi Date: Wed, 30 Oct 2024 12:22:16 +0100 Subject: [PATCH] fix: update asana usage (#693) --- scripts/release/asana-create-tasks.js | 39 +++++++++++++++++---------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/scripts/release/asana-create-tasks.js b/scripts/release/asana-create-tasks.js index 740a5a0cb..9c60e6b39 100644 --- a/scripts/release/asana-create-tasks.js +++ b/scripts/release/asana-create-tasks.js @@ -67,23 +67,32 @@ const duplicateTemplateTask = (templateTaskGid) => { return asana.tasks.duplicateTask(templateTaskGid, duplicateOption) } -const waitForJobSuccess = async (job_gid, attempts = 1) => { - const interval = 500 +const waitForJobSuccess = async (job_gid) => { + const interval = 1000 const maxAttempts = 20 return new Promise(async (resolve, reject) => { - const { status } = await asana.jobs.getJob(job_gid) - if (status === 'succeeded') { - return resolve(status) + const innerFn = async function (job_gid, attempts) { + console.error(`Waiting for job ${job_gid} to complete...`) + const { status } = await asana.jobs.getJob(job_gid) + console.error(`Job ${job_gid} status: ${status}`) + if (status === 'succeeded') { + return resolve(status) + } + attempts += 1 + + if (attempts > maxAttempts) { + const errMsg = `The job ${job_gid} took too long to execute` + console.error(errMsg) + return reject(new Error(errMsg)) + } + + console.error(`Retrying in ${interval}ms...`) + await timersPromises.setTimeout(interval) + console.error(`Attempt ${attempts}`) + return innerFn(job_gid, attempts) } - attempts += 1 - - if (attempts > maxAttempts) { - return reject(new Error(`The job ${job_gid} took too long to execute`)) - } - - await timersPromises.setTimeout(interval) - return waitForJobSuccess(job_gid, attempts) + return innerFn(job_gid, 1) }) } @@ -101,6 +110,8 @@ const asanaCreateTasks = async () => { .replace('[[release_url]]', getLink(releaseUrl, 'Autofill Release')) .replace('[[notes]]', releaseNotes) .replace(/<\/?p>/ig, '\n') + // Asana supports only h1 and h2 + .replace(/<(h3|h4)>/ig, '

').replace(/<\/(h3|h4)>/ig, '

') // Updating task and moving to Release section... await asana.tasks.updateTask(new_task.gid, {html_notes: updatedNotes}) @@ -136,7 +147,7 @@ const asanaCreateTasks = async () => { await asana.tasks.updateTask(gid, { name: newName, html_notes: subtaskNotes }) for (const projectGid of projectGids) { - await asana.tasks.addProjectForTask(gid, { project: projectGid, insert_after: null }) + await asana.tasks.addProjectForTask(gid, { project: projectGid }) } }