mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -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 * as nls from 'vs/nls';
|
||||||
import { Registry } from 'vs/platform/registry/common/platform';
|
import { Registry } from 'vs/platform/registry/common/platform';
|
||||||
import { WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
import { WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||||
|
import { IntervalTimer } from 'vs/base/common/async';
|
||||||
|
|
||||||
const insightRegistry = Registry.as<IInsightRegistry>(Extensions.InsightContribution);
|
const insightRegistry = Registry.as<IInsightRegistry>(Extensions.InsightContribution);
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
|||||||
|
|
||||||
private _typeKey: string;
|
private _typeKey: string;
|
||||||
private _init: boolean = false;
|
private _init: boolean = false;
|
||||||
|
private _intervalTimer: IntervalTimer;
|
||||||
|
|
||||||
public error: string;
|
public error: string;
|
||||||
public lastUpdated: string;
|
public lastUpdated: string;
|
||||||
@@ -76,6 +78,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
|||||||
result => {
|
result => {
|
||||||
if (this._init) {
|
if (this._init) {
|
||||||
this._updateChild(result);
|
this._updateChild(result);
|
||||||
|
this.setupInterval();
|
||||||
} else {
|
} else {
|
||||||
this.queryObv = Observable.fromPromise(Promise.resolve<SimpleExecuteResult>(result));
|
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(
|
this._register(toDisposableSubscription(this.queryObv.subscribe(
|
||||||
result => {
|
result => {
|
||||||
this._updateChild(result);
|
this._updateChild(result);
|
||||||
|
this.setupInterval();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
this.showError(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 {
|
private showError(error: string): void {
|
||||||
this.error = error;
|
this.error = error;
|
||||||
this._cd.detectChanges();
|
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());
|
this.lastUpdated = nls.localize('insights.lastUpdated', "Last Updated: {0} {1}", date.toLocaleTimeString(), date.toLocaleDateString());
|
||||||
if (this._init) {
|
if (this._init) {
|
||||||
this._updateChild(storedResult.results);
|
this._updateChild(storedResult.results);
|
||||||
|
this.setupInterval();
|
||||||
this._cd.detectChanges();
|
this._cd.detectChanges();
|
||||||
} else {
|
} else {
|
||||||
this.queryObv = Observable.fromPromise(Promise.resolve<SimpleExecuteResult>(JSON.parse(storage)));
|
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');
|
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)
|
if (!types.isStringArray(this.insightConfig.query)
|
||||||
&& !types.isString(this.insightConfig.query)
|
&& !types.isString(this.insightConfig.query)
|
||||||
&& !types.isString(this.insightConfig.queryFile)) {
|
&& !types.isString(this.insightConfig.queryFile)) {
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ export const insightsSchema: IJSONSchema = {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
description: nls.localize('insightQueryFileDescription', '[Optional] path to a file that contains a query. Use if "query" is not set')
|
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: {
|
details: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
|||||||
@@ -56,4 +56,5 @@ export interface IInsightsConfig {
|
|||||||
query?: string | Array<string>;
|
query?: string | Array<string>;
|
||||||
queryFile?: string;
|
queryFile?: string;
|
||||||
details?: IInsightsConfigDetails;
|
details?: IInsightsConfigDetails;
|
||||||
|
autoRefreshInterval?: number;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user