@axa-fr/slimfaas-planet-saver 0.36.20-pr.1081138 → 0.36.20
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/README.md +33 -19
- package/package.json +1 -1
- package/src/SlimFaasPlanetSaver.d.ts +1 -1
- package/src/SlimFaasPlanetSaver.js +6 -6
package/README.md
CHANGED
|
@@ -41,9 +41,9 @@ const PlanetSaver = ({ children, baseUrl, fetch, noActivityTimeout=60000, behavi
|
|
|
41
41
|
fetch,
|
|
42
42
|
behavior,
|
|
43
43
|
updateCallback: (data) => {
|
|
44
|
-
// Filter only the items that block the UI (WakeUp+
|
|
44
|
+
// Filter only the items that block the UI (WakeUp+BlockUI)
|
|
45
45
|
const blockingItems = data.filter(
|
|
46
|
-
(item) => instance.getBehavior(item.Name) === 'WakeUp+
|
|
46
|
+
(item) => instance.getBehavior(item.Name) === 'WakeUp+BlockUI'
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
// If all blocking items are ready, set isFirstStart to false
|
|
@@ -89,6 +89,20 @@ export default PlanetSaver;
|
|
|
89
89
|
|
|
90
90
|
|
|
91
91
|
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Usage:
|
|
95
|
+
|
|
96
|
+
```jsx
|
|
97
|
+
const behavior: {
|
|
98
|
+
"api-speech-to-text": "WakeUp",
|
|
99
|
+
"heavy-pdf-service": "WakeUp+BlockUI",
|
|
100
|
+
"deprecated-service": "None"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
<PlanetSaver baseUrl="http://slimfaas.mycompany.com" fetch={window.fetch} behavior={behavior}>
|
|
104
|
+
<App />
|
|
105
|
+
</PlanetSaver>
|
|
92
106
|
```
|
|
93
107
|
|
|
94
108
|
---
|
|
@@ -108,26 +122,26 @@ This will launch a local dev server, letting you see `SlimFaasPlanetSaver` in ac
|
|
|
108
122
|
## Configuration Options
|
|
109
123
|
When you create a `new SlimFaasPlanetSaver(baseUrl, options)`, you can provide the following optional properties in the `options` object:
|
|
110
124
|
|
|
111
|
-
| Property | Type
|
|
112
|
-
|
|
113
|
-
| updateCallback | `(data: any[]) => void`
|
|
114
|
-
| errorCallback | `(errorMessage: string) => void`
|
|
115
|
-
| interval | `number`
|
|
116
|
-
| overlayStartingMessage | `string`
|
|
117
|
-
| overlayNoActivityMessage | `string`
|
|
118
|
-
| overlayErrorMessage | `string`
|
|
119
|
-
| overlaySecondaryMessage | `string`
|
|
120
|
-
| overlayErrorSecondaryMessage | `string`
|
|
121
|
-
| overlayLoadingIcon | `string`
|
|
122
|
-
| noActivityTimeout | `number`
|
|
123
|
-
| wakeUpTimeout | `number`
|
|
124
|
-
| fetch | `typeof fetch`
|
|
125
|
-
| behavior | `{ [functionName: string]: 'WakeUp+
|
|
125
|
+
| Property | Type | Default | Description |
|
|
126
|
+
|---------------------------|----------------------------------------------------------------------|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
127
|
+
| updateCallback | `(data: any[]) => void` | `() => {}` | Function called after a successful fetch of the functions’ status. The array data includes objects with info about each function, for example: `[{ Name: 'myFunc', NumberReady: 1 }, ...]`. |
|
|
128
|
+
| errorCallback | `(errorMessage: string) => void` | `() => {}` | Function called if an error occurs during the status fetch (e.g., network error). Receives an errorMessage string. |
|
|
129
|
+
| interval | `number` | `5000` | How frequently (in ms) the polling should run. |
|
|
130
|
+
| overlayStartingMessage | `string` | `"🌳 Starting the environment.... 🌳"` | Main message shown on the overlay when the environment is waking up. |
|
|
131
|
+
| overlayNoActivityMessage | `string` | `"Waiting activity to start environment..."` | Message shown if there is no user activity (mouse movement) for too long, but the environment is not ready yet. |
|
|
132
|
+
| overlayErrorMessage | `string` | `"An error occurred while starting the environment."` | Main message shown on the overlay if an error occurs (e.g., network error). |
|
|
133
|
+
| overlaySecondaryMessage | `string` | `"Startup should be fast, but if no machines are available it can take several minutes."` | Secondary message shown on the overlay when the environment is waking up. |
|
|
134
|
+
| overlayErrorSecondaryMessage | `string` | `"If the error persists, please contact an administrator."` | Secondary message shown on the overlay when an error occurs. |
|
|
135
|
+
| overlayLoadingIcon | `string` | `"🌍"` | Text or icon shown on the overlay. By default, it is animated to spin. |
|
|
136
|
+
| noActivityTimeout | `number` | `60000` | How long (in ms) to wait for mouse movement before concluding there is no activity. If no activity is detected, a different overlay message is displayed. |
|
|
137
|
+
| wakeUpTimeout | `number` | `60000` | If a function was recently “woken up,” we’ll skip re-calling wake-up for that function within this timeout window (in ms). |
|
|
138
|
+
| fetch | `typeof fetch` | Global fetch | Custom fetch function if you want to provide your own (e.g., for SSR, or if your environment doesn't have a global fetch). |
|
|
139
|
+
| behavior | `{ [functionName: string]: 'WakeUp+BlockUI' \| 'WakeUp' \| 'None' }` | *Not set; defaults each function to "WakeUp+BlockUI" if unspecified* | Allows you to override how each function is handled: 1. `"WakeUp+BlockUI"`: wakes the function and blocks the UI with the overlay until it’s ready. 2. `"WakeUp"`: wakes without blocking the UI. 3. `"None"`: no wake-up call. |
|
|
126
140
|
|
|
127
141
|
### Notes on Behavior
|
|
128
|
-
If a function is **not** specified in the behavior map, it defaults to `"WakeUp+
|
|
142
|
+
If a function is **not** specified in the behavior map, it defaults to `"WakeUp+BlockUI"`.
|
|
129
143
|
|
|
130
|
-
- `"WakeUp+
|
|
144
|
+
- `"WakeUp+BlockUI"` means the overlay will be shown until that function is `NumberReady >= 1`.
|
|
131
145
|
- `"WakeUp"` means we attempt to wake up the function, but do not keep the overlay shown specifically for that function.
|
|
132
146
|
- `"None"` means the function will neither be woken up nor block the UI.
|
|
133
147
|
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ export default class SlimFaasPlanetSaver {
|
|
|
23
23
|
this.fetch = options.fetch || fetch;
|
|
24
24
|
|
|
25
25
|
// Ajout de la configuration de comportement
|
|
26
|
-
// Les valeurs possibles sont "WakeUp+
|
|
26
|
+
// Les valeurs possibles sont "WakeUp+BlockUI", "WakeUp", "None"
|
|
27
27
|
this.behavior = options.behavior || {};
|
|
28
28
|
|
|
29
29
|
this.intervalId = null;
|
|
@@ -39,10 +39,10 @@ export default class SlimFaasPlanetSaver {
|
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Retourne le comportement à appliquer pour une fonction donnée
|
|
42
|
-
* S'il n'est pas renseigné, renvoie "WakeUp+
|
|
42
|
+
* S'il n'est pas renseigné, renvoie "WakeUp+BlockUI" par défaut
|
|
43
43
|
*/
|
|
44
44
|
getBehavior(name) {
|
|
45
|
-
return this.behavior[name] || 'WakeUp+
|
|
45
|
+
return this.behavior[name] || 'WakeUp+BlockUI';
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
initialize() {
|
|
@@ -78,7 +78,7 @@ export default class SlimFaasPlanetSaver {
|
|
|
78
78
|
// On évite de rappeler trop souvent la même fonction
|
|
79
79
|
const shouldFilter = lastWakeUpTime && (currentTime - lastWakeUpTime) <= this.wakeUpTimeout;
|
|
80
80
|
|
|
81
|
-
// On ne fait un wake-up que pour les fonctions dont le comportement est "WakeUp" ou "WakeUp+
|
|
81
|
+
// On ne fait un wake-up que pour les fonctions dont le comportement est "WakeUp" ou "WakeUp+BlockUI"
|
|
82
82
|
const wakePromises = data
|
|
83
83
|
.filter((item) => this.getBehavior(item.Name) !== 'None')
|
|
84
84
|
.filter((item) => item.NumberReady === 0 || !shouldFilter)
|
|
@@ -113,8 +113,8 @@ export default class SlimFaasPlanetSaver {
|
|
|
113
113
|
}
|
|
114
114
|
const data = await response.json();
|
|
115
115
|
|
|
116
|
-
// On ne considère comme bloquantes que les fonctions dont le comportement est "WakeUp+
|
|
117
|
-
const blockingItems = data.filter((item) => this.getBehavior(item.Name) === 'WakeUp+
|
|
116
|
+
// On ne considère comme bloquantes que les fonctions dont le comportement est "WakeUp+BlockUI"
|
|
117
|
+
const blockingItems = data.filter((item) => this.getBehavior(item.Name) === 'WakeUp+BlockUI');
|
|
118
118
|
const allBlockingReady = blockingItems.every((item) => item.NumberReady >= 1);
|
|
119
119
|
|
|
120
120
|
// Si toutes les fonctions "bloquantes" sont prêtes, on estime que c'est "ready".
|