Skip to content

retry find files if nothing is returned #1615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions src/manifest/dbtWorkspaceFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,54 @@ export class DBTWorkspaceFolder implements Disposable {
return allowListFolders;
}

private async retryWithBackoff<T>(
fn: () => Thenable<T>,
retries: number = 5,
backoff: number = 1000,
): Promise<T> {
let attempt = 0;
while (attempt < retries) {
try {
const result = await fn();
if (Array.isArray(result) && result.length === 0) {
this.dbtTerminal.debug(
"discoverProjects",
"no projects found. retrying...",
false,
);
throw new Error("no projects found. retrying");
}
return result;
} catch (error) {
attempt++;
if (attempt >= retries) {
throw error;
}
await new Promise((resolve) => setTimeout(resolve, backoff * attempt));
}
}
this.dbtTerminal.debug(
"discoverProjects",
"no projects found after maximum retries",
false,
);
throw new Error("no projects found after maximum retries");
}

async discoverProjects() {
// Ignore dbt_packages and venv/site-packages/dbt project folders
const excludePattern = "**/{dbt_packages,site-packages}";
const dbtProjectFiles = await workspace.findFiles(
new RelativePattern(
this.workspaceFolder,
`**/${DBTProject.DBT_PROJECT_FILE}`,
),
new RelativePattern(this.workspaceFolder, excludePattern),
const dbtProjectFiles = await this.retryWithBackoff(
() =>
workspace.findFiles(
new RelativePattern(
this.workspaceFolder,
`**/${DBTProject.DBT_PROJECT_FILE}`,
),
new RelativePattern(this.workspaceFolder, excludePattern),
),
5,
1000,
);
this.dbtTerminal.info(
"discoverProjects",
Expand Down