Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix Space drip scheduling

Anand Baburajan8d0cb767a48b
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index bf7f53fc4f..8500733160 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -1374,7 +1374,7 @@ func setupAndStartCrons(userAuthRepo *repo.UserAuthRepository, collectionLinkRep
emailNotificationCtrl.SendStorageWarningMails()
})
- schedule(c, "@every 24h", func() {
+ scheduleAndRun(c, "@every 24h", func() {
spaceDripController.ProcessSpaceDrips()
})
diff --git a/server/space/controller/drips.go b/server/space/controller/drips.go
index 326b929d9b..c1c09f422f 100644
--- a/server/space/controller/drips.go
+++ b/server/space/controller/drips.go
@@ -65,9 +65,10 @@ func (c *SpaceDripController) ProcessSpaceDrips() {
}
if c.LockController != nil {
if !c.LockController.TryLock(spaceDripMailLock, timeutil.MicrosecondsAfterHours(24)) {
- log.Info("Skipping space drip emails because the daily lock is held")
+ log.Info("Skipping space drip emails because another instance is running")
return
}
+ defer c.LockController.ReleaseLock(spaceDripMailLock)
}
stats, err := c.processSpaceDrips(context.Background(), timeutil.Microseconds())
if err != nil {
@@ -169,6 +170,12 @@ func (c *SpaceDripController) processSpaceDripStage(ctx context.Context, stage s
if err != nil {
return 0, err
}
+ if len(candidates) == limit {
+ log.WithFields(log.Fields{
+ "template_id": stage.TemplateID,
+ "batch_size": limit,
+ }).Warn("Space drip candidate batch reached limit")
+ }
userIDs := make([]int64, 0, len(candidates))
for _, candidate := range candidates {
if _, handled := handledThisRun[candidate.UserID]; handled {
diff --git a/server/space/controller/drips_test.go b/server/space/controller/drips_test.go
index 34bc220765..fbf047d64f 100644
--- a/server/space/controller/drips_test.go
+++ b/server/space/controller/drips_test.go
@@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
)
-func TestProcessSpaceDripsKeepsDailyLock(t *testing.T) {
+func TestProcessSpaceDripsReleasesLock(t *testing.T) {
testutil.WithServerRoot(t)
db := testutil.RequireTestDB(t)
testutil.ResetTables(t, db)
@@ -38,9 +38,9 @@ func TestProcessSpaceDripsKeepsDailyLock(t *testing.T) {
controller.ProcessSpaceDrips()
- var lockUntil int64
- require.NoError(t, db.QueryRow(`SELECT lock_until FROM task_lock WHERE task_name = $1`, spaceDripMailLock).Scan(&lockUntil))
- require.Greater(t, lockUntil, timeutil.Microseconds())
+ var lockCount int
+ require.NoError(t, db.QueryRow(`SELECT COUNT(*) FROM task_lock WHERE task_name = $1`, spaceDripMailLock).Scan(&lockCount))
+ require.Zero(t, lockCount)
}
func TestSpaceDripsSendMatureProfileNudgeOnly(t *testing.T) {