|
64 | 64 | }, |
65 | 65 |
|
66 | 66 | /** |
67 | | - * Once the page is mounted set a function to run every 5 seconds that will |
| 67 | + * Once the page is mounted set a function to run every 10 seconds that will |
68 | 68 | * iterate through the visible servers and fetch their resource usage. |
69 | 69 | */ |
70 | 70 | mounted: function () { |
71 | | - this._iterateServerResourceUse(); |
| 71 | + window.setTimeout(() => { |
| 72 | + this._iterateServerResourceUse(); |
| 73 | + }, 5000); |
72 | 74 | }, |
73 | 75 |
|
74 | 76 | computed: { |
|
133 | 135 | } |
134 | 136 |
|
135 | 137 | window.events.$emit(`server:${server.uuid}::resources`, response.data.attributes); |
136 | | - }) |
137 | | - .catch(err => { |
138 | | - console.error(err); |
139 | 138 | }); |
140 | 139 | }, |
141 | 140 |
|
|
144 | 143 | * |
145 | 144 | * @private |
146 | 145 | */ |
147 | | - _iterateServerResourceUse: function (initialTimeout = 5000) { |
148 | | - window.setTimeout(() => { |
149 | | - if (this.documentVisible) { |
150 | | - return window.setTimeout(this._iterateServerResourceUse(), 5000); |
151 | | - } |
152 | | - }, initialTimeout); |
| 146 | + _iterateServerResourceUse: function (loop = true) { |
| 147 | + // Try again in 10 seconds, window is not in the foreground. |
| 148 | + if (!this.documentVisible && loop) { |
| 149 | + window.setTimeout(() => { |
| 150 | + this._iterateServerResourceUse(); |
| 151 | + }, 10000); |
| 152 | + } |
| 153 | +
|
| 154 | + this.servers.forEach(server => { |
| 155 | + this.getResourceUse(server); |
| 156 | + }); |
| 157 | +
|
| 158 | + if (loop) { |
| 159 | + window.setTimeout(() => { |
| 160 | + this._iterateServerResourceUse(); |
| 161 | + }, 10000); |
| 162 | + } |
153 | 163 | }, |
154 | 164 |
|
155 | 165 | /** |
|
167 | 177 | // If it has been more than 30 seconds since this window was put into the background |
168 | 178 | // lets go ahead and refresh all of the listed servers so that they have fresh stats. |
169 | 179 | const diff = differenceInSeconds(new Date(), this.backgroundedAt); |
170 | | - this._iterateServerResourceUse(diff > 30 ? 1 : 5000); |
| 180 | + if (diff > 30) { |
| 181 | + this._iterateServerResourceUse(false); |
| 182 | + } |
171 | 183 | }, |
172 | 184 | } |
173 | 185 | }; |
|
0 commit comments