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

fix(agent): move timers initialization from constructor to initialize. #3205

Merged
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions clients/tabby-agent/src/codeCompletion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class CompletionProvider implements Feature {
private readonly completionDebounce = new CompletionDebounce();
private readonly completionStats = new CompletionStats();

private readonly submitStatsTimer: ReturnType<typeof setInterval>;
private submitStatsTimer: ReturnType<typeof setInterval> | undefined = undefined;

private lspConnection: Connection | undefined = undefined;
private clientCapabilities: ClientCapabilities | undefined = undefined;
Expand All @@ -80,12 +80,7 @@ export class CompletionProvider implements Feature {
private readonly anonymousUsageLogger: AnonymousUsageLogger,
private readonly gitContextProvider: GitContextProvider,
private readonly recentlyChangedCodeSearch: RecentlyChangedCodeSearch,
) {
const submitStatsInterval = 1000 * 60 * 60 * 24; // 24h
this.submitStatsTimer = setInterval(async () => {
await this.submitStats();
}, submitStatsInterval);
}
) {}

initialize(connection: Connection, clientCapabilities: ClientCapabilities): ServerCapabilities {
this.lspConnection = connection;
Expand Down Expand Up @@ -113,6 +108,12 @@ export class CompletionProvider implements Feature {
connection.onNotification(TelemetryEventNotification.type, async (param) => {
return this.postEvent(param);
});

const submitStatsInterval = 1000 * 60 * 60 * 24; // 24h
this.submitStatsTimer = setInterval(async () => {
await this.submitStats();
}, submitStatsInterval);

return serverCapabilities;
}

Expand Down
18 changes: 9 additions & 9 deletions clients/tabby-agent/src/http/tabbyApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,13 @@ export class TabbyApiClient extends EventEmitter {

private healthCheckMutexAbortController: AbortController | undefined = undefined;

private readonly reconnectTimer: ReturnType<typeof setInterval>;
private reconnectTimer: ReturnType<typeof setInterval> | undefined = undefined;

constructor(
private readonly configurations: Configurations,
private readonly anonymousUsageLogger: AnonymousUsageLogger,
) {
super();

const reconnectInterval = 1000 * 30; // 30s
this.reconnectTimer = setInterval(async () => {
if (this.status === "noConnection" || this.status === "unauthorized") {
this.logger.debug("Trying to reconnect...");
await this.connect();
}
}, reconnectInterval);
}

async initialize(clientInfo: ClientInfo | undefined) {
Expand All @@ -91,6 +83,14 @@ export class TabbyApiClient extends EventEmitter {
this.connect(); // no await
}
});

const reconnectInterval = 1000 * 30; // 30s
this.reconnectTimer = setInterval(async () => {
if (this.status === "noConnection" || this.status === "unauthorized") {
this.logger.debug("Trying to reconnect...");
await this.connect();
}
}, reconnectInterval);
}

async shutdown() {
Expand Down
Loading