Skip to content

Commit

Permalink
Retry failed requests and ignore error getting job info (#11)
Browse files Browse the repository at this point in the history
* install axios-retry package

* Use retry and handle error getting job info (fail for other requests)

* better error reporting
  • Loading branch information
chamini2 authored Aug 11, 2022
1 parent 95e6693 commit 48d1f43
Show file tree
Hide file tree
Showing 220 changed files with 8,140 additions and 3 deletions.
31 changes: 28 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const axios = require('axios');
const core = require('@actions/core');
const fs = require('fs');
const axiosRetry = require('axios-retry');

axiosRetry(axios, {
retryDelay: (retryCount) => retryCount * 1000,
retries: 3,
shouldResetTimeout: true,
onRetry: (retryCount, error, requestConfig) => {
console.error("Error in request. Retrying...")
}
});

const run_status = {
1: 'Queued',
Expand All @@ -13,7 +23,7 @@ const run_status = {

const dbt_cloud_api = axios.create({
baseURL: 'https://cloud.getdbt.com/api/v2/',
timeout: 1000,
timeout: 5000, // 5 seconds
headers: {
'Authorization': `Token ${core.getInput('dbt_cloud_token')}`,
'Content-Type': 'application/json'
Expand All @@ -38,8 +48,18 @@ async function runJob(account_id, job_id, cause, git_sha) {
}

async function getJobRun(account_id, run_id) {
let res = await dbt_cloud_api.get(`/accounts/${account_id}/runs/${run_id}/`);
return res.data;
try {
let res = await dbt_cloud_api.get(`/accounts/${account_id}/runs/${run_id}/`);
return res.data;
} catch (e) {
let errorMsg = e.toString()
if (errorMsg.search("timeout of ") != -1 && errorMsg.search(" exceeded") != -1) {
// Special case for axios timeout
errorMsg += ". The dbt Cloud API is taking too long to respond."
}

console.error("Error getting job information from dbt Cloud. " + errorMsg);
}
}

async function getArtifacts(account_id, run_id) {
Expand Down Expand Up @@ -72,6 +92,11 @@ async function executeAction() {
while (true) {
await sleep(core.getInput('interval') * 1000);
let res = await getJobRun(account_id, run_id);
if (!res) {
// Restart loop if there is no response
continue;
}

let run = res.data;

core.info(`Run: ${run.id} - ${run_status[run.status]}`);
Expand Down
36 changes: 36 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions node_modules/@babel/runtime/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions node_modules/@babel/runtime/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions node_modules/@babel/runtime/helpers/AsyncGenerator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions node_modules/@babel/runtime/helpers/AwaitValue.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions node_modules/@babel/runtime/helpers/applyDecoratedDescriptor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 48d1f43

Please sign in to comment.