BackgroundJobsWorker.coffee 708 B

123456789101112131415161718192021
  1. settings = require('settings-sharelatex')
  2. TpdsPollingBackgroundTasks = require("./app/js/Features/ThirdPartyDataStore/TpdsPollingBackgroundTasks")
  3. time =
  4. oneHour : 60 * 60 * 1000
  5. fifteenMinutes : 15 * 60 * 1000
  6. thirtySeconds : 30 * 1000
  7. betweenThirtyAndFiveHundredSeconds: =>
  8. random = Math.floor(Math.random() * 500) * 1000
  9. if random < time.thirtySeconds
  10. return time.betweenThirtyAndFiveHundredSeconds()
  11. else
  12. return random
  13. runPeriodically = (funcToRun, periodLength)->
  14. recursiveReference = ->
  15. funcToRun ->
  16. setTimeout recursiveReference, periodLength
  17. setTimeout recursiveReference, 0
  18. runPeriodically ((cb) -> TpdsPollingBackgroundTasks.pollUsersWithDropbox(cb)), time.fifteenMinutes