-
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.
Create timer to automatically purge expired claims (#80)
* Add PurgeClaims timer * Update logging level in PurgeClaims timer
- Loading branch information
Showing
4 changed files
with
33 additions
and
2 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
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,14 @@ | ||
import AppLogger from "../client/appLogger"; | ||
import Claim from "../database/entities/app/Claim"; | ||
|
||
export default async function PurgeClaims() { | ||
const claims = await Claim.FetchAll(Claim); | ||
|
||
const whenLastClaimable = new Date(Date.now() - (1000 * 60 * 5)); // 5 minutes ago | ||
|
||
const expiredClaims = claims.filter(x => x.WhenCreated < whenLastClaimable); | ||
|
||
await Claim.RemoveMany(Claim, expiredClaims); | ||
|
||
AppLogger.LogInfo("Timers/PurgeClaims", `Purged ${expiredClaims.length} claims from the database`); | ||
} |