Fix: save action on give-clue

This commit is contained in:
Grail Finder
2025-07-04 12:44:15 +03:00
parent c2d6812230
commit 058d501774
3 changed files with 44 additions and 3 deletions

View File

@ -24,6 +24,7 @@ func (cm *CronManager) Start() {
go func() {
for range ticker.C {
cm.CleanupRooms()
cm.CleanupActions()
}
}()
}
@ -99,3 +100,31 @@ func (cm *CronManager) CleanupRooms() {
}
}
func (cm *CronManager) CleanupActions() {
ctx, tx, err := cm.repo.InitTx(context.Background())
if err != nil {
cm.log.Error("failed to init transaction for actions cleanup", "err", err)
return
}
defer func() {
if r := recover(); r != nil {
if err := tx.Rollback(); err != nil {
cm.log.Error("failed to rollback transaction for actions cleanup", "err", err)
}
panic(r)
}
}()
if err := cm.repo.ActionsDeleteOrphaned(ctx); err != nil {
cm.log.Error("failed to delete orphaned actions", "err", err)
if err := tx.Rollback(); err != nil {
cm.log.Error("failed to rollback transaction for actions cleanup", "err", err)
}
return
}
if err := tx.Commit(); err != nil {
cm.log.Error("failed to commit transaction for actions cleanup", "err", err)
}
}