BackgroundJobsWorker.coffee 1.2 KB

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