eip-cloud-services 1.1.10 → 1.1.11
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eip-cloud-services",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
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':
|