@nexrender/core 1.60.3 → 1.60.6
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 +2 -2
- package/src/helpers/timeout.js +20 -0
- package/src/tasks/download.js +5 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexrender/core",
|
|
3
|
-
"version": "1.60.
|
|
3
|
+
"version": "1.60.6",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"author": "Inlife",
|
|
6
6
|
"homepage": "https://www.nexrender.com",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "11a6be2cf0daffc3da0acfcacbf53cdd84ab434f"
|
|
47
47
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const withTimeout = (promise, timeoutMs, errorMsg) => {
|
|
2
|
+
let timeoutHandle;
|
|
3
|
+
|
|
4
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
5
|
+
timeoutHandle = setTimeout(() => {
|
|
6
|
+
reject(new Error(errorMsg));
|
|
7
|
+
}, timeoutMs);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
return Promise.race([
|
|
11
|
+
promise,
|
|
12
|
+
timeoutPromise,
|
|
13
|
+
]).finally(() => {
|
|
14
|
+
clearTimeout(timeoutHandle);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
withTimeout,
|
|
20
|
+
};
|
package/src/tasks/download.js
CHANGED
|
@@ -7,6 +7,9 @@ const uri2path = require('file-uri-to-path')
|
|
|
7
7
|
const data2buf = require('data-uri-to-buffer')
|
|
8
8
|
const mime = require('mime-types')
|
|
9
9
|
const {expandEnvironmentVariables} = require('../helpers/path')
|
|
10
|
+
const { withTimeout } = require('../helpers/timeout');
|
|
11
|
+
|
|
12
|
+
const NEXRENDER_DOWNLOAD_TIMEOUT = process.env.NEXRENDER_DOWNLOAD_TIMEOUT || 3 * 60 * 1000; // 3 minutes timeout by default
|
|
10
13
|
|
|
11
14
|
const download = (job, settings, asset) => {
|
|
12
15
|
if (asset.type == 'data') return Promise.resolve();
|
|
@@ -104,7 +107,7 @@ const download = (job, settings, asset) => {
|
|
|
104
107
|
|
|
105
108
|
const stream = fs.createWriteStream(asset.dest)
|
|
106
109
|
|
|
107
|
-
return new Promise((resolve, reject) => {
|
|
110
|
+
return withTimeout(new Promise((resolve, reject) => {
|
|
108
111
|
const errorHandler = (error) => {
|
|
109
112
|
reject(new Error({reason: 'Unable to download file', meta: {src, error}}))
|
|
110
113
|
};
|
|
@@ -116,7 +119,7 @@ const download = (job, settings, asset) => {
|
|
|
116
119
|
stream
|
|
117
120
|
.on('error', errorHandler)
|
|
118
121
|
.on('finish', resolve)
|
|
119
|
-
})
|
|
122
|
+
}), NEXRENDER_DOWNLOAD_TIMEOUT, 'Download timed out for asset ' + asset.src)
|
|
120
123
|
});
|
|
121
124
|
|
|
122
125
|
case 'file':
|