diff options
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/ServicesStore.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 6064b9929..fa31dc292 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -165,10 +165,19 @@ export default class ServicesStore extends Store { | |||
165 | */ | 165 | */ |
166 | _serviceMaintenance() { | 166 | _serviceMaintenance() { |
167 | this.all.forEach((service) => { | 167 | this.all.forEach((service) => { |
168 | // Defines which services should be hibernated. | 168 | // Defines which services should be hibernated or woken up |
169 | if (!service.isActive && (Date.now() - service.lastUsed > ms(`${this.stores.settings.all.app.hibernationStrategy}s`))) { | 169 | if (!service.isActive) { |
170 | // If service is stale, hibernate it. | 170 | if (!service.lastHibernated && (Date.now() - service.lastUsed > ms(`${this.stores.settings.all.app.hibernationStrategy}s`))) { |
171 | this._hibernate({ serviceId: service.id }); | 171 | // If service is stale, hibernate it. |
172 | this._hibernate({ serviceId: service.id }); | ||
173 | } | ||
174 | |||
175 | if (service.lastHibernated && Number(this.stores.settings.all.app.wakeUpStrategy) > 0) { | ||
176 | // If service is in hibernation and the wakeup time has elapsed, wake it. | ||
177 | if ((Date.now() - service.lastHibernated > ms(`${this.stores.settings.all.app.wakeUpStrategy}s`))) { | ||
178 | this._awake({ serviceId: service.id }); | ||
179 | } | ||
180 | } | ||
172 | } | 181 | } |
173 | 182 | ||
174 | if (service.lastPoll && (service.lastPoll - service.lastPollAnswer > ms('1m'))) { | 183 | if (service.lastPoll && (service.lastPoll - service.lastPollAnswer > ms('1m'))) { |
@@ -473,12 +482,11 @@ export default class ServicesStore extends Store { | |||
473 | if (!keepActiveRoute) this.stores.router.push('/'); | 482 | if (!keepActiveRoute) this.stores.router.push('/'); |
474 | const service = this.one(serviceId); | 483 | const service = this.one(serviceId); |
475 | 484 | ||
476 | this.all.forEach((s, index) => { | 485 | this.all.forEach((s) => { |
477 | this.all[index].isActive = false; | 486 | s.isActive = false; |
478 | }); | 487 | }); |
479 | service.isActive = true; | 488 | service.isActive = true; |
480 | this._awake({ serviceId: service.id }); | 489 | this._awake({ serviceId: service.id }); |
481 | service.lastUsed = Date.now(); | ||
482 | 490 | ||
483 | if (this.isTodosServiceActive && !this.stores.todos.settings.isFeatureEnabledByUser) { | 491 | if (this.isTodosServiceActive && !this.stores.todos.settings.isFeatureEnabledByUser) { |
484 | this.actions.todos.toggleTodosFeatureVisibility(); | 492 | this.actions.todos.toggleTodosFeatureVisibility(); |
@@ -824,20 +832,22 @@ export default class ServicesStore extends Store { | |||
824 | return; | 832 | return; |
825 | } | 833 | } |
826 | if (service.isActive) { | 834 | if (service.isActive) { |
827 | debug('Skipping service hibernation'); | 835 | debug(`Skipping service hibernation for ${service.name}`); |
828 | return; | 836 | return; |
829 | } | 837 | } |
830 | 838 | ||
831 | debug(`Hibernate ${service.name}`); | 839 | debug(`Hibernate ${service.name}`); |
832 | 840 | ||
833 | service.isHibernationRequested = true; | 841 | service.isHibernationRequested = true; |
842 | service.lastHibernated = Date.now(); | ||
834 | } | 843 | } |
835 | 844 | ||
836 | @action _awake({ serviceId }) { | 845 | @action _awake({ serviceId }) { |
837 | debug('Waking up from service hibernation'); | ||
838 | const service = this.one(serviceId); | 846 | const service = this.one(serviceId); |
847 | debug(`Waking up from service hibernation for ${service.name}`); | ||
839 | service.isHibernationRequested = false; | 848 | service.isHibernationRequested = false; |
840 | service.liveFrom = Date.now(); | 849 | service.lastUsed = Date.now(); |
850 | service.lastHibernated = null; | ||
841 | } | 851 | } |
842 | 852 | ||
843 | @action _resetLastPollTimer({ serviceId = null }) { | 853 | @action _resetLastPollTimer({ serviceId = null }) { |