pixl-server-storage 3.1.3 → 3.1.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/engines/S3.js +19 -1
- package/package.json +1 -1
- package/storage.js +34 -6
- package/README.md +0 -1273
package/engines/S3.js
CHANGED
|
@@ -7,6 +7,7 @@ var Component = require("pixl-server/component");
|
|
|
7
7
|
var Tools = require("pixl-tools");
|
|
8
8
|
var Cache = require("pixl-cache");
|
|
9
9
|
var S3 = require("@aws-sdk/client-s3");
|
|
10
|
+
var { NodeHttpHandler } = require("@aws-sdk/node-http-handler");
|
|
10
11
|
var streamToBuffer = require("fast-stream-to-buffer");
|
|
11
12
|
|
|
12
13
|
module.exports = Class.create({
|
|
@@ -83,6 +84,16 @@ module.exports = Class.create({
|
|
|
83
84
|
this.s3Params = combo_config.params || {};
|
|
84
85
|
delete combo_config.params;
|
|
85
86
|
|
|
87
|
+
// allow user to specify HTTP timeout options for S3
|
|
88
|
+
if (combo_config.connectTimeout || combo_config.socketTimeout) {
|
|
89
|
+
combo_config.requestHandler = new NodeHttpHandler({
|
|
90
|
+
connectionTimeout: combo_config.connectTimeout || 0,
|
|
91
|
+
socketTimeout: combo_config.socketTimeout || 0
|
|
92
|
+
});
|
|
93
|
+
delete combo_config.connectTimeout;
|
|
94
|
+
delete combo_config.socketTimeout;
|
|
95
|
+
}
|
|
96
|
+
|
|
86
97
|
this.s3 = new S3.S3Client(combo_config);
|
|
87
98
|
},
|
|
88
99
|
|
|
@@ -408,9 +419,16 @@ module.exports = Class.create({
|
|
|
408
419
|
self.logDebug(9, "S3 stream download closed: " + key);
|
|
409
420
|
} );
|
|
410
421
|
|
|
422
|
+
// get full length from the ContentRange header
|
|
423
|
+
var len = 0;
|
|
424
|
+
if (data.ContentRange && data.ContentRange.toString().match(/\/\s*(\d+)\s*$/)) {
|
|
425
|
+
len = parseInt( RegExp.$1 );
|
|
426
|
+
}
|
|
427
|
+
|
|
411
428
|
callback( null, download, {
|
|
412
429
|
mod: Math.floor( (new Date(data.LastModified)).getTime() / 1000 ),
|
|
413
|
-
len:
|
|
430
|
+
len: len,
|
|
431
|
+
cr: data.ContentRange
|
|
414
432
|
} );
|
|
415
433
|
})
|
|
416
434
|
.catch( function(err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixl-server-storage",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "A key/value/list storage component for the pixl-server framework.",
|
|
5
5
|
"author": "Joseph Huckaby <jhuckaby@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/jhuckaby/pixl-server-storage",
|
package/storage.js
CHANGED
|
@@ -35,7 +35,8 @@ module.exports = Class.create({
|
|
|
35
35
|
max_recent_events: 0,
|
|
36
36
|
cache_key_match: '',
|
|
37
37
|
expiration_updates: false,
|
|
38
|
-
lower_case_keys: true
|
|
38
|
+
lower_case_keys: true,
|
|
39
|
+
queue_timeout: 30000
|
|
39
40
|
},
|
|
40
41
|
|
|
41
42
|
locks: null,
|
|
@@ -132,6 +133,7 @@ module.exports = Class.create({
|
|
|
132
133
|
this.maxRecentEvents = this.config.get('max_recent_events');
|
|
133
134
|
this.expHash = this.config.get('expiration_updates');
|
|
134
135
|
this.lowerKeys = this.config.get('lower_case_keys');
|
|
136
|
+
this.queueTimeout = this.config.get('queue_timeout');
|
|
135
137
|
|
|
136
138
|
this.cacheKeyRegex = null;
|
|
137
139
|
if (this.config.get('cache_key_match')) {
|
|
@@ -550,7 +552,8 @@ module.exports = Class.create({
|
|
|
550
552
|
var func = task;
|
|
551
553
|
task = { action: 'custom', handler: func };
|
|
552
554
|
}
|
|
553
|
-
|
|
555
|
+
task._id = Tools.generateShortID();
|
|
556
|
+
this.logDebug(9, "Enqueuing async task: " + task._id + ": " + (task.label || task.action),
|
|
554
557
|
this.debugLevel(10) ? task : null
|
|
555
558
|
);
|
|
556
559
|
this.queue.push( task );
|
|
@@ -559,10 +562,18 @@ module.exports = Class.create({
|
|
|
559
562
|
dequeue: function(task, callback) {
|
|
560
563
|
// run task and fire callback
|
|
561
564
|
var self = this;
|
|
562
|
-
this.logDebug(9, "Running async task: " + (task.label || task.action),
|
|
565
|
+
this.logDebug(9, "Running async task: " + task._id + ": " + (task.label || task.action),
|
|
563
566
|
this.debugLevel(10) ? task : null
|
|
564
567
|
);
|
|
565
568
|
|
|
569
|
+
// optional timeout for queue item execution
|
|
570
|
+
var timer = this.queueTimeout ? timer = setTimeout( function() {
|
|
571
|
+
self.logError('queue', "Async task timed out: " + task._id + ": " + (task.label || task.action), { ms: self.queueTimeout });
|
|
572
|
+
if (callback) callback();
|
|
573
|
+
callback = null;
|
|
574
|
+
timer = null;
|
|
575
|
+
}, this.queueTimeout ) : null;
|
|
576
|
+
|
|
566
577
|
switch (task.action) {
|
|
567
578
|
case 'expire_set':
|
|
568
579
|
// set expiration on record
|
|
@@ -585,7 +596,11 @@ module.exports = Class.create({
|
|
|
585
596
|
list_path: cleanup_list_path
|
|
586
597
|
});
|
|
587
598
|
|
|
588
|
-
|
|
599
|
+
if (timer) clearTimeout(timer);
|
|
600
|
+
timer = null;
|
|
601
|
+
|
|
602
|
+
if (callback) callback();
|
|
603
|
+
callback = null;
|
|
589
604
|
} ); // hashPut
|
|
590
605
|
} // expHash
|
|
591
606
|
else {
|
|
@@ -595,7 +610,11 @@ module.exports = Class.create({
|
|
|
595
610
|
list_path: cleanup_list_path
|
|
596
611
|
});
|
|
597
612
|
|
|
598
|
-
|
|
613
|
+
if (timer) clearTimeout(timer);
|
|
614
|
+
timer = null;
|
|
615
|
+
|
|
616
|
+
if (callback) callback();
|
|
617
|
+
callback = null;
|
|
599
618
|
}
|
|
600
619
|
} ); // listPush
|
|
601
620
|
break; // expire_set
|
|
@@ -604,7 +623,12 @@ module.exports = Class.create({
|
|
|
604
623
|
// custom handler
|
|
605
624
|
task.handler( task, function(err) {
|
|
606
625
|
if (err) self.logError('storage', "Failed to dequeue custom task: " + err);
|
|
607
|
-
|
|
626
|
+
|
|
627
|
+
if (timer) clearTimeout(timer);
|
|
628
|
+
timer = null;
|
|
629
|
+
|
|
630
|
+
if (callback) callback();
|
|
631
|
+
callback = null;
|
|
608
632
|
} );
|
|
609
633
|
break; // custom
|
|
610
634
|
} // switch action
|
|
@@ -995,6 +1019,10 @@ module.exports = Class.create({
|
|
|
995
1019
|
last_second: this.lastSecondMetrics,
|
|
996
1020
|
last_minute: this.lastMinuteMetrics,
|
|
997
1021
|
recent_events: this.recentEvents,
|
|
1022
|
+
queue: {
|
|
1023
|
+
active: this.queue.running(),
|
|
1024
|
+
pending: this.queue.length()
|
|
1025
|
+
},
|
|
998
1026
|
locks: {}
|
|
999
1027
|
};
|
|
1000
1028
|
|