Documentation Index
Fetch the complete documentation index at: https://docs.jelou.ai/llms.txt
Use this file to discover all available pages before exploring further.
Execute tarefas periódicas: limpe dados expirados, sincronize registros, gere relatórios. Sua função dispara automaticamente de acordo com o schedule que você configurar.
Padrão: config.cron + guard isCron + secrets para conexões externas.
import { define, z } from "@jelou/functions";
export default define({
name: "cleanup-job",
description: "Cleans expired sessions and syncs records",
input: z.object({}),
config: {
cron: [
{ expression: "0 3 * * *", timezone: "UTC" },
{ expression: "0 15 * * 1-5", timezone: "America/Guayaquil" },
],
mcp: false,
},
handler: async (_input, ctx) => {
if (!ctx.isCron) {
return { skipped: true, reason: "only runs via cron" };
}
ctx.log("Running cleanup", { cron: ctx.trigger.cron });
const dbUrl = ctx.env.get("DATABASE_URL");
const apiKey = ctx.env.get("EXTERNAL_API_KEY");
const staleRecords = await fetch(`${dbUrl}/api/sessions?expired=true`)
.then((r) => r.json());
let cleaned = 0;
for (const record of staleRecords) {
await fetch(`${dbUrl}/api/sessions/${record.id}`, {
method: "DELETE",
headers: { Authorization: `Bearer ${apiKey}` },
});
cleaned++;
}
ctx.log("Cleanup completed", { cleaned, total: staleRecords.length });
return { cleaned, checked: staleRecords.length };
},
});
jelou secrets set cleanup-job DATABASE_URL=https://db.example.com EXTERNAL_API_KEY=YOUR_API_KEY
config.cron define quando executa. Você pode ter múltiplos schedules com fusos horários diferentes.
- O guard
if (!ctx.isCron) evita que alguém execute a limpeza acidentalmente via HTTP.
config.mcp: false — uma tarefa de manutenção não é uma ferramenta de IA.
ctx.trigger.cron informa qual schedule acionou a execução.