@pronto-tools-and-more/network-process 6.0.0 → 6.1.0

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@pronto-tools-and-more/network-process",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "",
5
5
  "main": "src/networkProcessMain.js",
6
6
  "type": "module",
@@ -0,0 +1 @@
1
+ export const ProcessingResources = "E_PROCESSING_RESOURCES";
@@ -0,0 +1,3 @@
1
+ export const isProcessingResourcesResponse = (response) => {
2
+ return response === "PROCESSING_RESOURCES";
3
+ };
@@ -0,0 +1,8 @@
1
+ import * as ErrorCodes from "../ErrorCodes/ErrorCodes.js";
2
+
3
+ export class ProcessingResourcesError extends Error {
4
+ constructor() {
5
+ super("Processing resources");
6
+ this.code = ErrorCodes.ProcessingResources;
7
+ }
8
+ }
@@ -0,0 +1,5 @@
1
+ import { setTimeout } from "node:timers/promises";
2
+
3
+ export const wait = async (delay) => {
4
+ await setTimeout(delay);
5
+ };
@@ -1,9 +1,12 @@
1
1
  import { VError } from "@lvce-editor/verror";
2
- import { openAsBlob } from "fs";
3
2
  import ky from "ky";
3
+ import { openAsBlob } from "node:fs";
4
4
  import * as Assert from "../Assert/Assert.js";
5
5
  import * as GetFormData from "../GetFormData/GetFormData.js";
6
6
  import * as GetXr from "../GetXr/GetXr.js";
7
+ import * as IsProcessingResourcesResponse from "../IsProcessingResourcesResponse/IsProcessingResourcesResponse.js";
8
+ import { ProcessingResourcesError } from "../ProcessingResourcesError/ProcessingResourcesError.js";
9
+ import * as Timeout from "../Timeout/Timeout.js";
7
10
 
8
11
  const getHeaders = () => {
9
12
  const xr = GetXr.getXr();
@@ -20,6 +23,8 @@ export const uploadZip = async ({
20
23
  sessionId,
21
24
  uploadTimeout,
22
25
  message,
26
+ maxRetries = 10,
27
+ waitBetweenRetries = 60_000,
23
28
  }) => {
24
29
  try {
25
30
  Assert.string(file);
@@ -46,7 +51,11 @@ export const uploadZip = async ({
46
51
  },
47
52
  timeout: uploadTimeout,
48
53
  });
49
- return response.text();
54
+ const text = await response.text();
55
+ if (IsProcessingResourcesResponse.isProcessingResourcesResponse(text)) {
56
+ throw new ProcessingResourcesError();
57
+ }
58
+ return text;
50
59
  } catch (error) {
51
60
  // @ts-ignore
52
61
  if (error && error.name === "HTTPError") {
@@ -61,6 +70,27 @@ export const uploadZip = async ({
61
70
  throw new Error(`Failed to upload zip file: Server ${serverMessage}`);
62
71
  }
63
72
  }
73
+ if (error && error instanceof ProcessingResourcesError) {
74
+ if (maxRetries > 0) {
75
+ console.info(
76
+ `[pronto-network-process] processing resources error, retrying ${maxRetries} more times in ${waitBetweenRetries}ms`
77
+ );
78
+ await Timeout.wait(waitBetweenRetries);
79
+ return uploadZip({
80
+ file,
81
+ uploadBaseUrl,
82
+ preview,
83
+ appId,
84
+ sessionId,
85
+ uploadTimeout,
86
+ message,
87
+ maxRetries: maxRetries - 1,
88
+ waitBetweenRetries,
89
+ });
90
+ } else {
91
+ throw new Error(`Failed to upload zip: Processing resources error`);
92
+ }
93
+ }
64
94
  throw new VError(error, `Failed to upload zip`);
65
95
  }
66
96
  };