Tweak speed for crons

This commit is contained in:
Neeraj Gupta 2024-03-11 10:31:35 +05:30 committed by Neeraj Gupta
parent 192caedeb9
commit e667eef951
2 changed files with 16 additions and 3 deletions

View file

@ -855,14 +855,14 @@ func setupAndStartCrons(userAuthRepo *repo.UserAuthRepository, publicCollectionR
}
})
schedule(c, "@every 193s", func() {
schedule(c, "@every 2m", func() {
fileController.CleanupDeletedFiles()
})
schedule(c, "@every 101s", func() {
embeddingCtrl.CleanupDeletedEmbeddings()
})
schedule(c, "@every 120s", func() {
schedule(c, "@every 5m", func() {
trashController.DropFileMetadataCron()
})

View file

@ -5,6 +5,7 @@ import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"runtime/debug"
"strconv"
"strings"
@ -54,6 +55,9 @@ const MaxFileSize = int64(1024 * 1024 * 1024 * 5)
// MaxUploadURLsLimit indicates the max number of upload urls which can be request in one go
const MaxUploadURLsLimit = 50
const (
DeletedObjectQueueLock = "deleted_objects_queue_lock"
)
// Create adds an entry for a file in the respective tables
func (c *FileController) Create(ctx context.Context, userID int64, file ente.File, userAgent string, app ente.App) (ente.File, error) {
@ -600,7 +604,16 @@ func (c *FileController) CleanupDeletedFiles() {
defer func() {
c.cleanupCronRunning = false
}()
items, err := c.QueueRepo.GetItemsReadyForDeletion(repo.DeleteObjectQueue, 200)
lockStatus := c.LockController.TryLock(DeletedObjectQueueLock, time.MicrosecondsAfterHours(24))
if !lockStatus {
log.Warning(fmt.Sprintf("Failed to acquire lock %s", DeletedObjectQueueLock))
return
}
defer func() {
c.LockController.ReleaseLock(DeletedObjectQueueLock)
}()
items, err := c.QueueRepo.GetItemsReadyForDeletion(repo.DeleteObjectQueue, 2000)
if err != nil {
log.WithError(err).Error("Failed to fetch items from queue")
return