Skip to content

Commit

Permalink
run delete authtoken in background (#627)
Browse files Browse the repository at this point in the history
* try 3 times to create authtoken prefect input

* remove returning response

* increase axios timeout

* remove timeout option in request options

* delete authtoken in prefect in the background

* add try..catch

---------

Co-authored-by: suwarno ong <[email protected]>
  • Loading branch information
SantanM and suwarnoong authored Jan 16, 2025
1 parent fc0ca35 commit 6f4000f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
21 changes: 15 additions & 6 deletions functions/jobplugins/src/services/CohortService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ export class CohortService {
);

await prefectApi.createInputAuthToken(flowRunId);
await new Promise((resolve) => {
setTimeout(async () => {
await prefectApi.deleteInputAuthToken(flowRunId);
resolve(`Deleted the input of ${flowRunId}`);
}, 5000);
});
Promise.any([
new Promise(() => {
setTimeout(async () => {
const msg = "Prefect input authtoken deletion";
try {
(await prefectApi.deleteInputAuthToken(flowRunId))
? console.log(`${msg} successful`)
: console.log(`${msg} failed`);
} catch (error) {
console.log(`${msg} failed`);
console.error(error);
}
}, 1000 * 60 * 5);
}),
]);

return { flowRunId };
}
Expand Down
17 changes: 12 additions & 5 deletions functions/jobplugins/src/services/DataCharacterizationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,19 @@ export class DataCharacterizationService {

await prefectApi.createInputAuthToken(flowRunId);

await Promise.any([
new Promise((resolve) => {
Promise.any([
new Promise(() => {
setTimeout(async () => {
await prefectApi.deleteInputAuthToken(flowRunId);
resolve(`Deleted the input of ${flowRunId}`);
}, 5000);
const msg = "Prefect input authtoken deletion";
try {
(await prefectApi.deleteInputAuthToken(flowRunId))
? console.log(`${msg} successful`)
: console.log(`${msg} failed`);
} catch (error) {
console.log(`${msg} failed`);
console.error(error);
}
}, 1000 * 60 * 5);
}),
]);

Expand Down
17 changes: 12 additions & 5 deletions functions/jobplugins/src/services/DataModelFlowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ export class DataModelFlowService {

await prefectApi.createInputAuthToken(flowRunId);

await Promise.any([
new Promise((resolve) => {
Promise.any([
new Promise(() => {
setTimeout(async () => {
await prefectApi.deleteInputAuthToken(flowRunId);
resolve(`Deleted the input of ${flowRunId}`);
}, 5000);
const msg = "Prefect input authtoken deletion";
try {
(await prefectApi.deleteInputAuthToken(flowRunId))
? console.log(`${msg} successful`)
: console.log(`${msg} failed`);
} catch (error) {
console.log(`${msg} failed`);
console.error(error);
}
}, 1000 * 60 * 5);
}),
]);

Expand Down
17 changes: 12 additions & 5 deletions functions/jobplugins/src/services/DbSvcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ export class DbSvcService {
);

await prefectApi.createInputAuthToken(flowrunId);
await Promise.any([
new Promise((resolve) => {
Promise.any([
new Promise(() => {
setTimeout(async () => {
await prefectApi.deleteInputAuthToken(flowrunId);
resolve(`Deleted the input of ${flowrunId}`);
}, 5000);
const msg = "Prefect input authtoken deletion";
try {
(await prefectApi.deleteInputAuthToken(flowrunId))
? console.log(`${msg} successful`)
: console.log(`${msg} failed`);
} catch (error) {
console.log(`${msg} failed`);
console.error(error);
}
}, 1000 * 60 * 5);
}),
]);

Expand Down
17 changes: 12 additions & 5 deletions functions/jobplugins/src/services/DqdService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ export class DqdService {

await prefectApi.createInputAuthToken(flowRunId);

await Promise.any([
new Promise((resolve) => {
Promise.any([
new Promise(() => {
setTimeout(async () => {
await prefectApi.deleteInputAuthToken(flowRunId);
resolve(`Deleted the input of ${flowRunId}`);
}, 5000);
const msg = "Prefect input authtoken deletion";
try {
(await prefectApi.deleteInputAuthToken(flowRunId))
? console.log(`${msg} successful`)
: console.log(`${msg} failed`);
} catch (error) {
console.log(`${msg} failed`);
console.error(error);
}
}, 1000 * 60 * 5);
}),
]);

Expand Down

0 comments on commit 6f4000f

Please sign in to comment.