increase_compile_timeouts.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const mongojs = require('../app/js/infrastructure/mongojs')
  2. const { db } = mongojs
  3. const async = require('async')
  4. const minilist = require('minimist')
  5. const newTimeout = 240
  6. const oldTimeoutLimits = {$gt: 60, $lt: 240}
  7. const updateUser = function (user, callback) {
  8. console.log(`Updating user ${user._id}`)
  9. const update = {
  10. $set: {
  11. 'features.compileTimeout': newTimeout
  12. }
  13. }
  14. db.users.update({
  15. _id: user._id,
  16. 'features.compileTimeout': oldTimeoutLimits
  17. }, update, callback)
  18. }
  19. const updateUsers = (users, callback) =>
  20. async.eachLimit(users, ASYNC_LIMIT, updateUser, function (error) {
  21. if (error) {
  22. callback(error)
  23. return
  24. }
  25. counter += users.length
  26. console.log(`${counter} users updated`)
  27. loopForUsers(callback)
  28. })
  29. var loopForUsers = callback =>
  30. db.users.find(
  31. { 'features.compileTimeout': oldTimeoutLimits },
  32. { 'features.compileTimeout': 1 }
  33. ).limit(FETCH_LIMIT, function (error, users) {
  34. if (error) {
  35. callback(error)
  36. return
  37. }
  38. if (users.length === 0) {
  39. console.log(`DONE (${counter} users updated)`)
  40. return callback()
  41. }
  42. updateUsers(users, callback)
  43. })
  44. var counter = 0
  45. var run = () =>
  46. loopForUsers(function (error) {
  47. if (error) { throw error }
  48. process.exit()
  49. })
  50. let FETCH_LIMIT, ASYNC_LIMIT
  51. var setup = function () {
  52. let args = minilist(process.argv.slice(2))
  53. FETCH_LIMIT = (args.fetch) ? args.fetch : 100
  54. ASYNC_LIMIT = (args.async) ? args.async : 10
  55. }
  56. setup()
  57. run()