BackgroundJobsWorker.coffee 989 B

12345678910111213141516171819202122232425
  1. settings = require('settings-sharelatex')
  2. SubscriptionBackgroundTasks = require("./app/js/Features/Subscription/SubscriptionBackgroundTasks")
  3. TpdsPollingBackgroundTasks = require("./app/js/Features/ThirdPartyDataStore/TpdsPollingBackgroundTasks")
  4. time =
  5. oneHour : 60 * 60 * 1000
  6. fifteenMinutes : 15 * 60 * 1000
  7. thirtySeconds : 30 * 1000
  8. betweenThirtyAndFiveHundredSeconds: =>
  9. random = Math.floor(Math.random() * 500) * 1000
  10. if random < time.thirtySeconds
  11. return time.betweenThirtyAndFiveHundredSeconds()
  12. else
  13. return random
  14. runPeriodically = (funcToRun, periodLength)->
  15. recursiveReference = ->
  16. funcToRun ->
  17. setTimeout recursiveReference, periodLength
  18. setTimeout recursiveReference, 0
  19. # TODO: Remove this one month after the ability to start free trials was removed
  20. runPeriodically ((cb) -> SubscriptionBackgroundTasks.downgradeExpiredFreeTrials(cb)), time.oneHour
  21. runPeriodically ((cb) -> TpdsPollingBackgroundTasks.pollUsersWithDropbox(cb)), time.fifteenMinutes