@axa-fr/slimfaas-planet-saver 0.35.12 → 0.35.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@axa-fr/slimfaas-planet-saver",
3
3
  "private": false,
4
- "version": "0.35.12",
4
+ "version": "0.35.13",
5
5
  "type": "module",
6
6
  "main": "./src/SlimFaasPlanetSaver.js",
7
7
  "module": "./src/SlimFaasPlanetSaver.js",
@@ -10,6 +10,7 @@
10
10
  private overlayErrorSecondaryMessage: string;
11
11
  private overlayLoadingIcon: string;
12
12
  private noActivityTimeout: number;
13
+ private wakeUpTimeout: number;
13
14
  private fetch: typeof fetch;
14
15
  private intervalId: number | null;
15
16
  private isDocumentVisible: boolean;
@@ -35,6 +36,7 @@
35
36
  overlayLoadingIcon?: string,
36
37
  fetch?: typeof fetch
37
38
  noActivityTimeout?: number
39
+ wakeUpTimeout?: number
38
40
  });
39
41
 
40
42
  initialize(): void;
@@ -19,6 +19,7 @@ export default class SlimFaasPlanetSaver {
19
19
  this.overlayErrorSecondaryMessage = options.overlayErrorSecondaryMessage || 'If the error persists, please contact an administrator.';
20
20
  this.overlayLoadingIcon = options.overlayLoadingIcon || '🌍';
21
21
  this.noActivityTimeout = options.noActivityTimeout || 60000;
22
+ this.wakeUpTimeout = options.wakeUpTimeout || 60000;
22
23
  this.fetch = options.fetch || fetch;
23
24
  this.intervalId = null;
24
25
  this.isDocumentVisible = !document.hidden;
@@ -28,6 +29,7 @@ export default class SlimFaasPlanetSaver {
28
29
  this.isReady = false;
29
30
  this.id = id++;
30
31
  this.cleanned = false;
32
+ this.lastWakeUpTime = null;
31
33
  }
32
34
 
33
35
  initialize() {
@@ -51,9 +53,12 @@ export default class SlimFaasPlanetSaver {
51
53
  this.isDocumentVisible = !document.hidden;
52
54
  }
53
55
 
54
- async wakeUpPods(data) {
56
+ async wakeUpPods(data, lastWakeUpTime) {
57
+ const currentTime = Date.now();
58
+ let isWakeUpCallMade = false;
59
+ const shouldFilter = lastWakeUpTime && (currentTime - lastWakeUpTime) <= this.wakeUpTimeout;
55
60
  const wakePromises = data
56
- .filter((item) => item.NumberReady === 0)
61
+ .filter((item) => item.NumberReady === 0 || !shouldFilter)
57
62
  .map(async (item) => {
58
63
  const response = await this.fetch(`${this.baseUrl}/wake-function/${item.Name}`, {
59
64
  method: 'POST',
@@ -61,6 +66,7 @@ export default class SlimFaasPlanetSaver {
61
66
  if (response.status >= 400) {
62
67
  throw new Error(`HTTP Error! status: ${response.status} for function ${item.Name}`);
63
68
  }
69
+ isWakeUpCallMade = true
64
70
  return response;
65
71
  });
66
72
 
@@ -70,6 +76,7 @@ export default class SlimFaasPlanetSaver {
70
76
  console.error("Error waking up pods:", error);
71
77
  throw error;
72
78
  }
79
+ return isWakeUpCallMade;
73
80
  }
74
81
 
75
82
  async fetchStatus() {
@@ -90,9 +97,19 @@ export default class SlimFaasPlanetSaver {
90
97
 
91
98
  if (!allReady && this.isDocumentVisible && !mouseMovedRecently) {
92
99
  this.updateOverlayMessage(this.overlayNoActivityMessage, 'waiting-action');
93
- } else if (!this.isDocumentVisible || mouseMovedRecently) {
94
- this.updateOverlayMessage(this.overlayStartingMessage, 'waiting');
95
- await this.wakeUpPods(data);
100
+ } else if (mouseMovedRecently && this.isDocumentVisible) {
101
+ if(!allReady) {
102
+ this.updateOverlayMessage(this.overlayStartingMessage, 'waiting');
103
+ }
104
+ if(!this.lastWakeUpTime) {
105
+ this.lastWakeUpTime = Date.now();
106
+ }
107
+ const isWakeUpCallMade = await this.wakeUpPods(data, this.lastWakeUpTime);
108
+ if(isWakeUpCallMade) {
109
+ this.lastWakeUpTime = Date.now();
110
+ }
111
+ } else if(!this.isDocumentVisible && !allReady) {
112
+ this.updateOverlayMessage(this.overlayNoActivityMessage, 'waiting');
96
113
  }
97
114
  } catch (error) {
98
115
  const errorMessage = error.message;