-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathdata-cleaner.ts
More file actions
22 lines (19 loc) · 788 Bytes
/
data-cleaner.ts
File metadata and controls
22 lines (19 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import periodService, { type PeriodQueryParam } from "@service/period-service"
import { keyOf } from "@util/period"
import { getBirthday, getStartOfDay, MILL_PER_DAY } from "@util/time"
import alarmManager from "./alarm-manager"
const PERIOD_ALARM_NAME = 'period-cleaner-alarm'
const START_DAY = keyOf(getBirthday())
const KEEP_RANGE_DAYS = 366
const cleanPeriodData = async () => {
const endDate = new Date().getTime() - MILL_PER_DAY * KEEP_RANGE_DAYS
const param: PeriodQueryParam = { periodRange: [START_DAY, keyOf(endDate)] }
await periodService.batchDeleteBetween(param)
}
export default function initDataCleaner() {
alarmManager.setWhen(
PERIOD_ALARM_NAME,
() => getStartOfDay(new Date()).getTime() + MILL_PER_DAY,
cleanPeriodData,
)
}