eip-cloud-services 1.1.10 → 1.1.12
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/cdn.js +19 -1
- package/src/mysql.js +10 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eip-cloud-services",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "Houses a collection of helpers for connecting with Cloud services.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,4 +24,4 @@
|
|
|
24
24
|
"mysql": "^2.18.1",
|
|
25
25
|
"redis": "^4.6.7"
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
}
|
package/src/cdn.js
CHANGED
|
@@ -11,6 +11,8 @@ const packageJson = require ( '../package.json' );
|
|
|
11
11
|
const { cwd } = require ( 'process' );
|
|
12
12
|
const { log } = config?.s3?.logsFunction ? require ( `${ cwd ()}/${config.s3.logsFunction}` ) : console;
|
|
13
13
|
|
|
14
|
+
const redis = require('./redis');
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Create a CDN invalidation for the specified key(s) and environment.
|
|
16
18
|
*
|
|
@@ -44,8 +46,24 @@ exports.createInvalidation = async ( cdn, key, environment = 'production' ) => {
|
|
|
44
46
|
throw new Error ( 'Invalid key argument. Expected a string or an array of strings.' );
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
if ( config?.redis?.host ) {
|
|
50
|
+
const redisKey = `cdn-invalidation:${cdn}:${environment}:${key}`;
|
|
51
|
+
const redisValue = await redis.get(redisKey);
|
|
52
|
+
|
|
53
|
+
if(redisValue) {
|
|
54
|
+
if ( config.cdn.log )
|
|
55
|
+
log ( `CDN [INVALIDATE]: Invalidation already in progress - skipping: ${paths.map ( path => `https://${cdn}${environment !== 'production' ? '-test' : ''}.eip.telegraph.co.uk${path}` ).join ( ', ' )}\n` );
|
|
56
|
+
await redis.increment(redisKey);
|
|
57
|
+
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
else{
|
|
61
|
+
await redis.set(redisKey, 1, cdnSettings.type === 'google' ? 300 : 120); // 5 minutes for google, 2 minutes for amazon
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
47
65
|
if ( config.cdn.log )
|
|
48
|
-
log ( `CDN [INVALIDATE]: ${paths.map ( path => `https://${cdn}${environment !== 'production' ? '-test' : ''}.eip.telegraph.co.uk
|
|
66
|
+
log ( `CDN [INVALIDATE]: ${paths.map ( path => `https://${cdn}${environment !== 'production' ? '-test' : ''}.eip.telegraph.co.uk${path}` ).join ( ', ' )}\n` );
|
|
49
67
|
|
|
50
68
|
switch ( cdnSettings.type ) {
|
|
51
69
|
case 'google':
|
package/src/mysql.js
CHANGED
|
@@ -27,9 +27,16 @@ const newQuery = ( connection, query ) => new Promise ( ( resolve, reject ) => {
|
|
|
27
27
|
connection.query ( query, ( error, results, fields ) => {
|
|
28
28
|
connection.release ();
|
|
29
29
|
if ( error ) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const MAX_ERROR_LENGTH = 500;
|
|
31
|
+
const MAX_QUERY_LENGTH = 300;
|
|
32
|
+
|
|
33
|
+
const shortError = (error?.stack || error?.message || String(error)).slice(0, MAX_ERROR_LENGTH);
|
|
34
|
+
const shortQuery = query.slice(0, MAX_QUERY_LENGTH);
|
|
35
|
+
|
|
36
|
+
console.error("Query Error:", shortError);
|
|
37
|
+
console.error("Truncated Query:", shortQuery);
|
|
38
|
+
|
|
39
|
+
reject(`There was a problem with query: ${shortError}`);
|
|
33
40
|
}
|
|
34
41
|
else {
|
|
35
42
|
resolve ( results );
|