You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
908 B
33 lines
908 B
import log4js from "logger";
|
|
import { dbGlobal } from "drizzle-pkg/lib/db";
|
|
import { agentSessions } from "drizzle-pkg/lib/schema/agent";
|
|
import { lt, and, isNotNull } from "drizzle-orm";
|
|
|
|
const logger = log4js.getLogger("SCHEDULER");
|
|
|
|
export default async function cleanupExpiredAgentSessions() {
|
|
try {
|
|
const now = new Date();
|
|
|
|
await dbGlobal
|
|
.delete(agentSessions)
|
|
.where(
|
|
and(
|
|
isNotNull(agentSessions.expiresAt),
|
|
lt(agentSessions.expiresAt, now),
|
|
),
|
|
);
|
|
|
|
logger.info("Agent session cleanup: expired temp sessions cleaned");
|
|
return {
|
|
success: true,
|
|
message: "Cleaned expired temp agent sessions",
|
|
};
|
|
} catch (err) {
|
|
logger.error(
|
|
"Agent session cleanup failed: %s",
|
|
err instanceof Error ? err.message : String(err),
|
|
);
|
|
return { success: false, message: "Agent session cleanup failed" };
|
|
}
|
|
}
|
|
|