Skip to content

Commit 6c7286d

Browse files
add rate limit and retry
1 parent ce95ecf commit 6c7286d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

scripts/update-docker.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function saveList(cb) {
7373
// stop all containers
7474
function stopAllContainers(cb) {
7575
debug('stopAllContainers');
76-
async.each(thisList, function(instance, next) {
76+
async.eachLimit(thisList, 10, function(instance, next) {
7777
stopInstance(instance.shortHash, next);
7878
}, cb);
7979
}
@@ -127,14 +127,16 @@ function getAllContainers(cb) {
127127

128128
function startAllContainers(instances, cb) {
129129
debug('instances');
130-
async.each(instances, function(shortHash, next) {
130+
ctx.retry = [];
131+
async.eachLimit(instances, 10, function(shortHash, next) {
131132
startInstance(shortHash, next);
132133
}, cb);
133134
}
134135

135136
function startInstance (shortHash, cb) {
136137
var Instance = user.fetchInstance(shortHash, function(err) {
137138
if (err) {
139+
ctx.retry.push(shortHash);
138140
ERRORS.push({
139141
func: 'startInstance:fetchInstance',
140142
err: err.message,
@@ -144,6 +146,7 @@ function startInstance (shortHash, cb) {
144146
}
145147
Instance.start(function(err) {
146148
if (err) {
149+
ctx.retry.push(shortHash);
147150
ERRORS.push({
148151
func: 'startInstance:start',
149152
err: err.message,
@@ -157,6 +160,12 @@ function startInstance (shortHash, cb) {
157160
});
158161
}
159162

163+
function retryStart (cb) {
164+
console.error('old errors', ERRORS);
165+
ERRORS = [];
166+
startInstance(ctx.retry, cb);
167+
}
168+
160169
// put back into mavis
161170
function addToMavis (cb) {
162171
debug('addToMavis');
@@ -186,6 +195,7 @@ function restore(cb) {
186195
async.waterfall([
187196
getAllContainers,
188197
startAllContainers,
198+
retryStart,
189199
addToMavis
190200
], cb);
191201
}

0 commit comments

Comments
 (0)