Make addons code remove a BoxError

This commit is contained in:
Girish Ramakrishnan
2019-12-04 13:17:58 -08:00
parent c992853cca
commit 53e39f571c
8 changed files with 154 additions and 177 deletions
+7 -5
View File
@@ -5,7 +5,7 @@ var assert = require('assert'),
authcodedb = require('./authcodedb.js'),
BoxError = require('./boxerror.js'),
debug = require('debug')('box:janitor'),
docker = require('./docker.js').connection,
Docker = require('dockerode'),
tokendb = require('./tokendb.js');
exports = module.exports = {
@@ -13,7 +13,9 @@ exports = module.exports = {
cleanupDockerVolumes: cleanupDockerVolumes
};
var NOOP_CALLBACK = function () { };
const NOOP_CALLBACK = function () { };
const gConnection = new Docker({ socketPath: '/var/run/docker.sock' });
function ignoreError(func) {
return function (callback) {
@@ -68,7 +70,7 @@ function cleanupTmpVolume(containerInfo, callback) {
debug('cleanupTmpVolume %j', containerInfo.Names);
docker.getContainer(containerInfo.Id).exec({ Cmd: cmd, AttachStdout: true, AttachStderr: true, Tty: false }, function (error, execContainer) {
gConnection.getContainer(containerInfo.Id).exec({ Cmd: cmd, AttachStdout: true, AttachStderr: true, Tty: false }, function (error, execContainer) {
if (error) return callback(new BoxError(BoxError.DOCKER_ERROR, `Failed to exec container: ${error.message}`));
execContainer.start({ hijack: true }, function (error, stream) {
@@ -77,7 +79,7 @@ function cleanupTmpVolume(containerInfo, callback) {
stream.on('error', callback);
stream.on('end', callback);
docker.modem.demuxStream(stream, process.stdout, process.stderr);
gConnection.modem.demuxStream(stream, process.stdout, process.stderr);
});
});
}
@@ -89,7 +91,7 @@ function cleanupDockerVolumes(callback) {
debug('Cleaning up docker volumes');
docker.listContainers({ all: 0 }, function (error, containers) {
gConnection.listContainers({ all: 0 }, function (error, containers) {
if (error) return callback(error);
async.eachSeries(containers, function (container, iteratorDone) {