31 lines
935 B
JavaScript
31 lines
935 B
JavaScript
const TASK = {
|
|
key: 'expired-session-sweep',
|
|
title: 'Expired session cleanup',
|
|
category: 'cleanup',
|
|
trigger: 'scheduled recurring task, hourly',
|
|
purpose: 'remove expired authentication sessions and their metadata.',
|
|
taskType: 'recurring-run',
|
|
intervalMs: 60 * 60 * 1000
|
|
};
|
|
|
|
function registerExpiredSessionSweepTask(options) {
|
|
const backgroundTaskQueue = options && options.backgroundTaskQueue;
|
|
const pool = options && options.pool;
|
|
|
|
if (!backgroundTaskQueue || !pool) {
|
|
throw new Error('registerExpiredSessionSweepTask requires the session cleanup dependencies.');
|
|
}
|
|
|
|
backgroundTaskQueue.registerRecurringTask({
|
|
key: TASK.key,
|
|
title: TASK.title,
|
|
category: TASK.category,
|
|
intervalMs: TASK.intervalMs,
|
|
metadata: {},
|
|
run: async function () {
|
|
await pool.query('DELETE FROM a_sessions WHERE expires_at <= NOW()');
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = { registerExpiredSessionSweepTask }; |