@@ -26,42 +26,55 @@ export class ExceptionlessClient {
2626 }
2727
2828 this . config . services . queue . onEventsPosted ( ( ) => Promise . resolve ( this . updateSettingsTimer ( ) ) ) ;
29+ await SettingsManager . applySavedServerSettings ( this . config ) ;
2930 }
3031
31- this . updateSettingsTimer ( configurationOrApiKey ? 5000 : 0 ) ;
32+ this . updateSettingsTimer ( ! ! configurationOrApiKey ) ;
3233 await EventPluginManager . startup ( new PluginContext ( this ) ) ;
33- await this . processQueue ( ) ;
34+ const { queue } = this . config . services ;
35+ await queue . startup ( ) ;
36+ if ( this . config . usePersistedQueueStorage ) {
37+ // TODO: Can we schedule this as part of startup?
38+ await queue . process ( ) ;
39+ }
3440 }
3541
3642 /** Submit events, pause any timers and go into low power mode. */
3743 public async suspend ( ) : Promise < void > {
3844 await EventPluginManager . suspend ( new PluginContext ( this ) ) ;
39- await this . processQueue ( ) ;
40- await this . config . services . queue . suspend ( ) ;
41- this . updateSettingsTimer ( 0 , - 1 ) ;
45+ const { queue } = this . config . services ;
46+ await queue . suspend ( ) ;
47+ await queue . process ( ) ;
48+ this . suspendSettingsTimer ( ) ;
49+ }
50+
51+ private suspendSettingsTimer ( ) : void {
52+ this . _timeoutId = clearTimeout ( this . _timeoutId ) ;
53+ this . _intervalId = clearInterval ( this . _intervalId ) ;
4254 }
4355
4456 public async processQueue ( ) : Promise < void > {
4557 await this . config . services . queue . process ( ) ;
4658 }
4759
48- // TODO: Look into better async scheduling..
49- private updateSettingsTimer ( initialDelay : number = 0 , updateWhenIdleInterval ?: number ) {
50- this . _timeoutId = clearTimeout ( this . _timeoutId ) ;
51- this . _intervalId = clearInterval ( this . _intervalId ) ;
60+ private updateSettingsTimer ( startingUp : boolean = false ) {
61+ this . suspendSettingsTimer ( ) ;
5262
53- const interval = updateWhenIdleInterval || this . config . updateSettingsWhenIdleInterval ;
63+ const interval = this . config . updateSettingsWhenIdleInterval ;
5464 if ( interval > 0 ) {
65+ let initialDelay : number = interval ;
66+ if ( startingUp ) {
67+ initialDelay = this . config . settingsVersion > 0 ? 15000 : 5000 ;
68+ }
69+
5570 this . config . services . log . info ( `Update settings every ${ interval } ms (${ initialDelay || 0 } ms delay)` ) ;
56- // TODO: Fix awaiting promise .
71+ // TODO: Look into better async scheduling. .
5772 const updateSettings = ( ) => void SettingsManager . updateSettings ( this . config ) ;
58- if ( initialDelay > 0 ) {
73+ if ( initialDelay < interval ) {
5974 this . _timeoutId = setTimeout ( updateSettings , initialDelay ) ;
6075 }
6176
6277 this . _intervalId = setInterval ( updateSettings , interval ) ;
63- } else {
64- this . config . services . log . info ( "Turning off update settings" ) ;
6578 }
6679 }
6780
0 commit comments