go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/apputil/jobs.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package apputil 9 10 import ( 11 "context" 12 "time" 13 14 "go.charczuk.com/sdk/cron" 15 ) 16 17 // DeleteExpiredSessions returns the job to delete expired sessions. 18 // 19 // The default cutoff is 14 days but we can tweak that a bit. 20 func DeleteExpiredSessions(mgr *ModelManager) cron.Job { 21 return cron.NewJob( 22 cron.OptJobName("delete_expired_sessions"), 23 cron.OptJobSchedule(cron.Every(5*time.Minute)), 24 cron.OptJobAction(func(ctx context.Context) error { 25 return mgr.DeleteExpiredSessions(ctx, time.Now().UTC().AddDate(0, 0, -14)) 26 }), 27 ) 28 }