-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautoRetryFailedCRR.js
More file actions
48 lines (45 loc) · 1.46 KB
/
autoRetryFailedCRR.js
File metadata and controls
48 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { waterfall, mapValuesLimit } = require('async');
const { Logger } = require('werelogs');
const CloudserverClient = require('./Clients/CloudserverClient');
const log = new Logger('s3utils::autoRetryFailedCRR');
const { ACCESS_KEY } = process.env;
const { SECRET_KEY } = process.env;
const { ENDPOINT } = process.env;
if (!ENDPOINT) {
throw new Error('ENDPOINT not defined!');
}
if (!ACCESS_KEY) {
throw new Error('ACCESS_KEY not defined');
}
if (!SECRET_KEY) {
throw new Error('SECRET_KEY not defined');
}
const cloudserverClient = new CloudserverClient(
ENDPOINT,
ACCESS_KEY,
SECRET_KEY,
);
waterfall([
next => cloudserverClient.getLocationsStatus(next),
(res, next) => {
const locations = res.status || {};
mapValuesLimit(locations, 3, (status, location, done) => {
cloudserverClient.listFailed({ Sitename: location }, (err, res) => {
if (err) {
return done(err);
}
if (res.Versions && res.Versions.length > 0) {
return cloudserverClient.retryFailedObjects({
Body: Buffer.from(JSON.stringify(res.Versions)),
}, done);
}
return done();
});
}, next);
},
], (err, res) => {
if (err) {
return log.error('error performing operation', { error: err });
}
return log.info('success retrying failed crr', { result: res });
});