[server] Release previous locks taken by host on statup
This commit is contained in:
parent
38e8f7c8d7
commit
c32f0a28f1
3 changed files with 21 additions and 1 deletions
|
@ -682,7 +682,7 @@ func main() {
|
|||
publicAPI.GET("/offers/black-friday", offerHandler.GetBlackFridayOffers)
|
||||
|
||||
setKnownAPIs(server.Routes())
|
||||
|
||||
lockController.ReleaseHostLock()
|
||||
setupAndStartBackgroundJobs(objectCleanupController, replicationController3)
|
||||
setupAndStartCrons(
|
||||
userAuthRepo, publicCollectionRepo, twoFactorRepo, passkeysRepo, fileController, taskLockingRepo, emailNotificationCtrl,
|
||||
|
|
|
@ -56,3 +56,11 @@ func (c *LockController) ReleaseLock(lockID string) {
|
|||
log.Errorf("Error while releasing lock %v: %s", lockID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *LockController) ReleaseHostLock() {
|
||||
count, err := c.TaskLockingRepo.ReleaseLocksBy(c.HostName)
|
||||
if err != nil {
|
||||
log.Errorf("Error while releasing host lock: %s", err)
|
||||
}
|
||||
log.Infof("Released %d locks held by %s", *count, c.HostName)
|
||||
}
|
||||
|
|
|
@ -71,6 +71,18 @@ func (repo *TaskLockRepository) ReleaseLock(name string) error {
|
|||
return stacktrace.Propagate(err, "")
|
||||
}
|
||||
|
||||
func (repo *TaskLockRepository) ReleaseLocksBy(lockedBy string) (*int64, error) {
|
||||
result, err := repo.DB.Exec(`DELETE FROM task_lock WHERE locked_by = $1`, lockedBy)
|
||||
if err != nil {
|
||||
return nil, stacktrace.Propagate(err, "")
|
||||
}
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return nil, stacktrace.Propagate(err, "")
|
||||
}
|
||||
return &rowsAffected, nil
|
||||
}
|
||||
|
||||
func (repo *TaskLockRepository) CleanupExpiredLocks() error {
|
||||
result, err := repo.DB.Exec(`DELETE FROM task_lock WHERE lock_until < $1`, time.Microseconds())
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue