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 1 commit
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
14 changes: 14 additions & 0 deletions src/dbt_client/dbtCloudIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,15 @@ export class DBTCloudProjectIntegration
}
}

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

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;
this.findAdapterType();
Copy link
Contributor

Choose a reason for hiding this comment

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

@mdesmet, should we add a telemetry event for retry and maybe for failure as well?

Copy link

Choose a reason for hiding this comment

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

Consider using await with this.findAdapterType() in retryOnce to ensure asynchronous operations are completed before proceeding.

}
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

Refine the retryOnce method for clarity and correctness

  • The variable firstRun is used to prevent multiple retries in the retryOnce method. However, the name firstRun may be misleading, as it suggests tracking the first execution of the entire process, whereas it's actually used to ensure that the retry logic occurs only once. Consider renaming it to hasRetried or retryAttempted to improve code readability.

  • The retryOnce method is declared as async, but it doesn't use await when calling this.findAdapterType(). If findAdapterType is an asynchronous function, you might want to await its completion to handle any potential errors. Alternatively, if you don't need to wait for findAdapterType() to complete, consider removing the async keyword from retryOnce.


private async findAdapterType() {
const adapterTypeCommand = this.dbtCloudCommand(
new DBTCommand("Getting adapter type...", [
Expand Down Expand Up @@ -1063,6 +1072,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