From 05aedf1e099e92b9c792ab579a01d1165cdbef82 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 31 Jul 2018 16:54:09 +0100 Subject: [PATCH 1/4] add script to increase paid compile timeouts to 240s --- .../web/scripts/increase_compile_timeouts.js | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 services/web/scripts/increase_compile_timeouts.js diff --git a/services/web/scripts/increase_compile_timeouts.js b/services/web/scripts/increase_compile_timeouts.js new file mode 100644 index 0000000000..8aa451545a --- /dev/null +++ b/services/web/scripts/increase_compile_timeouts.js @@ -0,0 +1,64 @@ +const mongojs = require('../app/js/infrastructure/mongojs') +const { db } = mongojs +const async = require('async') +const minilist = require('minimist') + +const newTimeout = 240 +const oldTimeoutLimits = {$gt: 60, $lt: 240} + +const updateUser = function (user, callback) { + console.log(`Updating user ${user._id}`) + const update = { + $set: { + 'features.compileTimeout': newTimeout + } + } + db.users.update({ + _id: user._id, + 'features.compileTimeout': oldTimeoutLimits + }, update, callback) +} + +const updateUsers = (users, callback) => + async.eachLimit(users, ASYNC_LIMIT, updateUser, function (error) { + if (error) { + callback(error) + return + } + counter += users.length + console.log(`${counter} users updated`) + loopForUsers(callback) + }) + +var loopForUsers = callback => + db.users.find( + { 'features.compileTimeout': oldTimeoutLimits }, + { 'features.compileTimeout': 1 } + ).limit(FETCH_LIMIT, function (error, users) { + if (error) { + callback(error) + return + } + if (users.length === 0) { + console.log(`DONE (${counter} users updated)`) + return callback() + } + updateUsers(users, callback) + }) + +var counter = 0 +var run = () => + loopForUsers(function (error) { + if (error) { throw error } + process.exit() + }) + +let FETCH_LIMIT, ASYNC_LIMIT +var setup = function () { + let args = minilist(process.argv.slice(2)) + FETCH_LIMIT = (args.fetch) ? args.fetch : 100 + ASYNC_LIMIT = (args.async) ? args.async : 10 +} + +setup() +run() From 7c9c0fbf06dc2420866e9e5441763b058a21fa0d Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 2 Aug 2018 13:49:56 +0100 Subject: [PATCH 2/4] add --all option for increase_compile_timeouts script --- services/web/scripts/increase_compile_timeouts.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/services/web/scripts/increase_compile_timeouts.js b/services/web/scripts/increase_compile_timeouts.js index 8aa451545a..69323134e9 100644 --- a/services/web/scripts/increase_compile_timeouts.js +++ b/services/web/scripts/increase_compile_timeouts.js @@ -26,8 +26,13 @@ const updateUsers = (users, callback) => return } counter += users.length - console.log(`${counter} users updated`) - loopForUsers(callback) + console.log(`${counter} users updated`); + if (DO_ALL) { + return loopForUsers(callback) + } else { + console.log('run again to continue updating'); + return callback() + } }) var loopForUsers = callback => @@ -53,11 +58,15 @@ var run = () => process.exit() }) -let FETCH_LIMIT, ASYNC_LIMIT +let FETCH_LIMIT, ASYNC_LIMIT, DO_ALL var setup = function () { let args = minilist(process.argv.slice(2)) + // --fetch N get N users each time FETCH_LIMIT = (args.fetch) ? args.fetch : 100 + // --async M run M updates in parallel ASYNC_LIMIT = (args.async) ? args.async : 10 + // --all means run to completion + DO_ALL = (args.all) } setup() From d6ab6ce6eececf0627b4439d98fc9418e5550916 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 2 Aug 2018 14:06:51 +0100 Subject: [PATCH 3/4] improve --all switch to remove fetch limit --- .../web/scripts/increase_compile_timeouts.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/services/web/scripts/increase_compile_timeouts.js b/services/web/scripts/increase_compile_timeouts.js index 69323134e9..6889f26962 100644 --- a/services/web/scripts/increase_compile_timeouts.js +++ b/services/web/scripts/increase_compile_timeouts.js @@ -30,7 +30,7 @@ const updateUsers = (users, callback) => if (DO_ALL) { return loopForUsers(callback) } else { - console.log('run again to continue updating'); + console.log('*** run again to continue updating ***') return callback() } }) @@ -66,7 +66,19 @@ var setup = function () { // --async M run M updates in parallel ASYNC_LIMIT = (args.async) ? args.async : 10 // --all means run to completion - DO_ALL = (args.all) + if (args.all) { + if (args.fetch) { + console.error('error: do not use --fetch with --all') + process.exit(1) + } else { + DO_ALL = true + // if we are updating for all users then ignore the fetch limit. + FETCH_LIMIT = 0 + // A limit() value of 0 (i.e. .limit(0)) is equivalent to setting + // no limit. + // https://docs.mongodb.com/manual/reference/method/cursor.limit + } + } } setup() From b9597358a959b22e9b2b002b5f8ff1108b57e57e Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 2 Aug 2018 14:14:23 +0100 Subject: [PATCH 4/4] lint fix --- services/web/scripts/increase_compile_timeouts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/scripts/increase_compile_timeouts.js b/services/web/scripts/increase_compile_timeouts.js index 6889f26962..185c563277 100644 --- a/services/web/scripts/increase_compile_timeouts.js +++ b/services/web/scripts/increase_compile_timeouts.js @@ -26,7 +26,7 @@ const updateUsers = (users, callback) => return } counter += users.length - console.log(`${counter} users updated`); + console.log(`${counter} users updated`) if (DO_ALL) { return loopForUsers(callback) } else {