Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav Ravichandran committed Nov 21, 2018
1 parent 87e7e5c commit 2b80b43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions helpers/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] };
Expand All @@ -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();
});
Expand Down
21 changes: 14 additions & 7 deletions plugins/caches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
};

Expand All @@ -370,20 +377,20 @@ exports.plugin = {
case 'pipelines': {
const pipelineIdParam = request.params.id;

payload.qs = {
opts.qs = {
pipelineId: pipelineIdParam
};

cachePath = `pipelines/${pipelineIdParam}`;
cachePath = `pipelines/${pipelineIdParam}/`;
break;
}
default:
return boom.forbidden('Invalid scope');
}

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);
Expand Down

0 comments on commit 2b80b43

Please sign in to comment.