Skip to content
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

feat: handled unknown dialect for cloud #1450

Closed
wants to merge 2 commits into from
Closed
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
27 changes: 26 additions & 1 deletion src/dbt_client/dbtCloudIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ export class DBTCloudProjectIntegration
}
if (!this.adapterType) {
// We only fetch the adapter type once, as it may impact compilation preview otherwise
this.findAdapterType();
const startTime = Date.now();
await this.findAdapterType();
const elapsedTime = Date.now() - startTime;
this.telemetry.sendTelemetryEvent("cloudFindAdapterTypeElapsedTime", {
elapsedTime: elapsedTime.toString(),
});
}
if (!this.version) {
await this.findVersion();
Expand Down Expand Up @@ -1023,6 +1028,21 @@ export class DBTCloudProjectIntegration
}
}

private firstRun = false;
private async retryOnce() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a return type to the retryOnce function signature for better clarity and refactoring ease.

Suggested change
private async retryOnce() {
private async retryOnce(): Promise<void> {

if (this.firstRun) {
return;
}
this.firstRun = true;
const startTime = Date.now();
await this.findAdapterType();
const elapsedTime = Date.now() - startTime;
this.telemetry.sendTelemetryEvent("cloudFindAdapterTypeElapsedTime", {
elapsedTime: elapsedTime.toString(),
retry: "true",
});
}

private async findAdapterType() {
const adapterTypeCommand = this.dbtCloudCommand(
new DBTCommand("Getting adapter type...", [
Expand Down Expand Up @@ -1063,6 +1083,11 @@ export class DBTCloudProjectIntegration
error,
);
}
if (!this.adapterType) {
setTimeout(() => {
this.retryOnce();
}, 5000);
}
Comment on lines +1086 to +1090
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider enhancing the retry mechanism.

The addition of a retry mechanism for adapter type detection is a good improvement for handling transient issues. However, there are a few points to consider:

  1. The current implementation might lead to multiple concurrent retries if findAdapterType is called multiple times in quick succession. Consider using a class-level flag to prevent this.

  2. There's no upper limit on the number of retries, which could lead to infinite retries in case of persistent issues. Consider implementing a maximum retry count.

  3. The retry is triggered in the findAdapterType method, but the actual retry logic is in retryOnce. This separation might make the flow harder to follow.

Here's a suggestion to address these points:

private retryCount = 0;
private readonly MAX_RETRIES = 3;
private isRetrying = false;

private async findAdapterType() {
  // ... existing code ...

  if (!this.adapterType && this.retryCount < this.MAX_RETRIES && !this.isRetrying) {
    this.retryCount++;
    this.isRetrying = true;
    setTimeout(async () => {
      await this.retryOnce();
      this.isRetrying = false;
    }, 5000);
  }
}

This approach limits the number of retries, prevents concurrent retries, and keeps the retry logic within the findAdapterType method for better clarity.

}

private async findVersion() {
Expand Down