forked from overleaf/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackgroundJobsWorker.coffee
27 lines (23 loc) · 1.15 KB
/
BackgroundJobsWorker.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
settings = require('settings-sharelatex')
SubscriptionBackgroundTasks = require("./app/js/Features/Subscription/SubscriptionBackgroundTasks")
TpdsPollingBackgroundTasks = require("./app/js/Features/ThirdPartyDataStore/TpdsPollingBackgroundTasks")
AutomaticSnapshotManager = require("./app/js/Features/Versioning/AutomaticSnapshotManager")
time =
oneHour : 60 * 60 * 1000
fifteenMinutes : 15 * 60 * 1000
thirtySeconds : 30 * 1000
betweenThirtyAndFiveHundredSeconds: =>
random = Math.floor(Math.random() * 500) * 1000
if random < time.thirtySeconds
return time.betweenThirtyAndFiveHundredSeconds()
else
return random
runPeriodically = (funcToRun, periodLength)->
recursiveReference = ->
funcToRun ->
setTimeout recursiveReference, periodLength
setTimeout recursiveReference, 0
# TODO: Remove this one month after the ability to start free trials was removed
runPeriodically ((cb) -> SubscriptionBackgroundTasks.downgradeExpiredFreeTrials(cb)), time.oneHour
runPeriodically ((cb) -> TpdsPollingBackgroundTasks.pollUsersWithDropbox(cb)), time.fifteenMinutes
runPeriodically ((cb) -> AutomaticSnapshotManager.takeAutomaticSnapshots(cb)), time.thirtySeconds