mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-26 01:25:38 -05:00
add auto refresh interval to insights (#1173)
This commit is contained in:
@@ -27,6 +27,7 @@ import * as pfs from 'vs/base/node/pfs';
|
||||
import * as nls from 'vs/nls';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
import { IntervalTimer } from 'vs/base/common/async';
|
||||
|
||||
const insightRegistry = Registry.as<IInsightRegistry>(Extensions.InsightContribution);
|
||||
|
||||
@@ -52,6 +53,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
||||
|
||||
private _typeKey: string;
|
||||
private _init: boolean = false;
|
||||
private _intervalTimer: IntervalTimer;
|
||||
|
||||
public error: string;
|
||||
public lastUpdated: string;
|
||||
@@ -76,6 +78,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
||||
result => {
|
||||
if (this._init) {
|
||||
this._updateChild(result);
|
||||
this.setupInterval();
|
||||
} else {
|
||||
this.queryObv = Observable.fromPromise(Promise.resolve<SimpleExecuteResult>(result));
|
||||
}
|
||||
@@ -100,6 +103,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
||||
this._register(toDisposableSubscription(this.queryObv.subscribe(
|
||||
result => {
|
||||
this._updateChild(result);
|
||||
this.setupInterval();
|
||||
},
|
||||
error => {
|
||||
this.showError(error);
|
||||
@@ -108,6 +112,14 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
||||
}
|
||||
}
|
||||
|
||||
private setupInterval(): void {
|
||||
if (this.insightConfig.autoRefreshInterval) {
|
||||
this._intervalTimer = new IntervalTimer();
|
||||
this._register(this._intervalTimer);
|
||||
this._intervalTimer.cancelAndSet(() => this.refresh(), this.insightConfig.autoRefreshInterval * 60 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private showError(error: string): void {
|
||||
this.error = error;
|
||||
this._cd.detectChanges();
|
||||
@@ -152,6 +164,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
||||
this.lastUpdated = nls.localize('insights.lastUpdated', "Last Updated: {0} {1}", date.toLocaleTimeString(), date.toLocaleDateString());
|
||||
if (this._init) {
|
||||
this._updateChild(storedResult.results);
|
||||
this.setupInterval();
|
||||
this._cd.detectChanges();
|
||||
} else {
|
||||
this.queryObv = Observable.fromPromise(Promise.resolve<SimpleExecuteResult>(JSON.parse(storage)));
|
||||
@@ -231,6 +244,10 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
||||
throw new Error('No query was specified for this insight');
|
||||
}
|
||||
|
||||
if (this.insightConfig.autoRefreshInterval && !types.isNumber(this.insightConfig.autoRefreshInterval)) {
|
||||
throw new Error('Auto Refresh Interval must be a number if specified');
|
||||
}
|
||||
|
||||
if (!types.isStringArray(this.insightConfig.query)
|
||||
&& !types.isString(this.insightConfig.query)
|
||||
&& !types.isString(this.insightConfig.queryFile)) {
|
||||
|
||||
@@ -32,6 +32,10 @@ export const insightsSchema: IJSONSchema = {
|
||||
type: 'string',
|
||||
description: nls.localize('insightQueryFileDescription', '[Optional] path to a file that contains a query. Use if "query" is not set')
|
||||
},
|
||||
autoRefreshInterval: {
|
||||
type: 'number',
|
||||
description: nls.localize('insightAutoRefreshIntervalDescription', '[Optional] Auto refresh interval in minutes, if not set, there will be no auto refresh')
|
||||
},
|
||||
details: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
|
||||
@@ -56,4 +56,5 @@ export interface IInsightsConfig {
|
||||
query?: string | Array<string>;
|
||||
queryFile?: string;
|
||||
details?: IInsightsConfigDetails;
|
||||
autoRefreshInterval?: number;
|
||||
}
|
||||
Reference in New Issue
Block a user