-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add auto-refresh time interval setting #2581
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,9 +37,11 @@ export class LogsController { | |
* @param {!angular.$interval} $interval | ||
* @param {!angular.$log} $log | ||
* @param {!../common/errorhandling/dialog.ErrorDialog} errorDialog | ||
* @param {!../common/settings/service.SettingsService} kdSettingsService | ||
* @ngInject | ||
*/ | ||
constructor(logsService, $sce, $document, $resource, $interval, $log, errorDialog) { | ||
constructor( | ||
logsService, $sce, $document, $resource, $interval, $log, errorDialog, kdSettingsService) { | ||
/** @private {!angular.$sce} */ | ||
this.sce_ = $sce; | ||
|
||
|
@@ -105,6 +107,12 @@ export class LogsController { | |
|
||
/** @export {number} Refresh interval in miliseconds. */ | ||
this.refreshInterval = 5000; | ||
|
||
/** @private {boolean} */ | ||
this.isIntervalRegistered_ = false; | ||
|
||
/** @private {!../common/settings/service.SettingsService} */ | ||
this.settingsService_ = kdSettingsService; | ||
} | ||
|
||
|
||
|
@@ -114,7 +122,7 @@ export class LogsController { | |
this.stateParams_ = this.$transition$.params(); | ||
this.updateUiModel(this.podLogs); | ||
this.topIndex = this.podLogs.logs.length; | ||
this.registerIntervalFunction_(); | ||
this.refreshInterval = this.settingsService_.getAutoRefreshTimeInterval() * 1000; | ||
} | ||
|
||
/** | ||
|
@@ -123,12 +131,15 @@ export class LogsController { | |
* @private | ||
*/ | ||
registerIntervalFunction_() { | ||
this.interval_(() => { | ||
if (this.logsService.getFollowing()) { | ||
this.loadNewest(); | ||
this.log_.info('Automatically refreshed logs'); | ||
} | ||
}, this.refreshInterval); | ||
if (!this.isIntervalRegistered_) { | ||
this.interval_(() => { | ||
if (this.logsService.getFollowing()) { | ||
this.loadNewest(); | ||
this.log_.info('Automatically refreshed logs'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd remove that to avoid unnecessary spam in a console. |
||
} | ||
}, this.refreshInterval); | ||
this.isIntervalRegistered_ = true; | ||
} | ||
} | ||
|
||
|
||
|
@@ -176,6 +187,7 @@ export class LogsController { | |
* @export | ||
*/ | ||
toggleLogFollow() { | ||
this.registerIntervalFunction_(); | ||
this.logsService.setFollowing(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By swapping this line with toggling interval we can get rid of below if statement. Logs will be reloaded immediately after first interval start. |
||
if (this.logsService.getFollowing()) { | ||
this.loadNewest(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After starting it, interval function will be running in the background forever. I'd start/stop whole interval function on button click. It returns a promise and
interval.cancel(promise)
can be used to stop it.