-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from EringiShimeji/auth/session-cleanup
期限切れのセッションを非同期に削除するジョブ
- Loading branch information
Showing
7 changed files
with
92 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package job | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"sudoku/repository" | ||
"time" | ||
) | ||
|
||
type SessionCleanupJob struct { | ||
sessionRepo repository.ISessionRepository | ||
interval time.Duration | ||
} | ||
|
||
func NewSessionCleanupJob(sessionRepo repository.ISessionRepository, interval time.Duration) *SessionCleanupJob { | ||
return &SessionCleanupJob{ | ||
sessionRepo: sessionRepo, | ||
interval: interval, | ||
} | ||
} | ||
|
||
func (j *SessionCleanupJob) Run(ctx context.Context) { | ||
log.Println("Starting session cleanup job") | ||
|
||
ticker := time.NewTicker(j.interval) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
log.Println("Session cleanup job stopped") | ||
return | ||
case <-ticker.C: | ||
if err := j.sessionRepo.DeleteExpired(); err != nil { | ||
log.Printf("Error during session cleanup: %v", err) | ||
} else { | ||
log.Println("Session cleanup completed successfully") | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters