From 2b80b43a597fc87d0feb1710fb52a3260c017b14 Mon Sep 17 00:00:00 2001 From: Pranav Ravichandran Date: Tue, 20 Nov 2018 10:52:52 -0800 Subject: [PATCH] Fixes --- helpers/aws.js | 6 +++--- plugins/caches.js | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/helpers/aws.js b/helpers/aws.js index 0a3e87e..ca7db8b 100644 --- a/helpers/aws.js +++ b/helpers/aws.js @@ -76,7 +76,7 @@ class AwsClient { return this.client.listObjects(params, (e, data) => { if (e) return callback(e); - if (data.isTruncated) return callback(); + if (data.Contents.length === 0) return callback(); params = { Bucket: this.bucket }; params.Delete = { Objects: [] }; @@ -85,9 +85,9 @@ class AwsClient { params.Delete.Objects.push({ Key: content.Key }); }); - return this.client.deleteObjects(params, (err, res) => { + return this.client.deleteObjects(params, (err) => { if (err) return callback(err); - if (res.isTruncated) return self.invalidateCache(this.bucket, callback); + if (data.isTruncated) return self.invalidateCache(cachePath, callback); return callback(); }); diff --git a/plugins/caches.js b/plugins/caches.js index 47418c4..afdb742 100644 --- a/plugins/caches.js +++ b/plugins/caches.js @@ -343,7 +343,7 @@ exports.plugin = { let cachePath; const apiUrl = config.get('ecosystem.api'); - const payload = { + const opts = { url: `${apiUrl}/v4/isAdmin`, method: 'GET', headers: { @@ -355,12 +355,19 @@ exports.plugin = { switch (request.params.scope) { case 'events': { - return h.response(); + const eventIdParam = request.params.id; + + opts.qs = { + eventId: eventIdParam + }; + + cachePath = `events/${eventIdParam}/`; + break; } case 'jobs': { const jobIdParam = request.params.id; - payload.qs = { + opts.qs = { jobId: jobIdParam }; @@ -370,11 +377,11 @@ exports.plugin = { case 'pipelines': { const pipelineIdParam = request.params.id; - payload.qs = { + opts.qs = { pipelineId: pipelineIdParam }; - cachePath = `pipelines/${pipelineIdParam}`; + cachePath = `pipelines/${pipelineIdParam}/`; break; } default: @@ -382,8 +389,8 @@ exports.plugin = { } try { - await req(payload, (err, response) => { - if (!err && response.statusCode === 200) { + await req(opts, (err, response) => { + if (!err && response === true) { return awsClient.invalidateCache(cachePath, (e) => { if (e) { console.log('Failed to invalidate cache: ', e);