1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00
Peertube/server/core/lib/schedulers/update-token-session-scheduler.ts
2025-07-30 11:42:49 +02:00

32 lines
842 B
TypeScript

import { MOAuthToken } from '@server/types/models/index.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
export class UpdateTokenSessionScheduler extends AbstractScheduler {
private static instance: UpdateTokenSessionScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.UPDATE_TOKEN_SESSION
private readonly toUpdate = new Set<MOAuthToken>()
private constructor () {
super()
}
addToUpdate (token: MOAuthToken) {
this.toUpdate.add(token)
}
protected async internalExecute () {
const toUpdate = Array.from(this.toUpdate)
this.toUpdate.clear()
for (const token of toUpdate) {
await token.save()
}
}
static get Instance () {
return this.instance || (this.instance = new this())
}
}