Configuración de cron jobs en Supabase para automatizar tareas
Clase 12 de 19 • Curso de Desarrollo Avanzado con Lovable
Resumen
Automating repetitive tasks in Supabase can save storage, reduce backend clicks, and improve user experience. Here you’ll see how a scheduled Supabase cron job plus an edge function can automatically delete user photos larger than five megabytes, with quick testing via SQL and simple monitoring through logs.
What is a Supabase cron job and what can it do?
Cron jobs are described as “little robots that run code every set time period you decide on.” They execute tasks on schedule without manual action. For example, running at midnight to email users who haven’t paid. In the project, the goal is to run a job every few minutes to delete photos over five megabytes, saving space.
How does the photo cleanup work every five minutes?
- Create an edge function named clean up large photos.
- Run it every five minutes via a cron schedule.
- Check the photos table for files above five megabytes.
- Delete the record from the table and the actual file from the user photos folder.
- Write logs so you can monitor what happened.
Why start in Lovable chat mode?
- Scan the codebase and generate a plan.
- Enable the necessary Supabase features to run cron jobs.
- Auto-generate the edge function and required SQL.
- Confirm deployment before testing.
- Produce a manual SQL trigger for quick verification without waiting for the schedule.
How to set up, test, and monitor the edge function?
The flow is straightforward: implement the plan suggested by Lovable, confirm deployment, test the function manually with SQL, and verify that large photos are removed from both the database and storage. Logs help ensure visibility and troubleshooting.
How do you manually trigger with SQL?
- Ask Lovable to generate an SQL statement to trigger the function.
- Open the Supabase SQL editor in your project.
- Paste the SQL and run it to test immediately.
- Confirm that photos above five megabytes disappear from your app.
What should you verify after deployment?
- The edge function exists and is deployed.
- The necessary SQL for the function is present.
- The cron schedule is set to every five minutes.
- Logs are available to review outcomes.
Which skills, concepts, and keywords stand out?
Building this automation highlights practical, repeatable workflows without deep specialization. The emphasis is on reading documentation, giving Lovable the right context, and letting it implement the pieces you need.
- Supabase cron job: scheduled execution that runs code automatically on a cadence you choose.
- Edge function: a callable function (clean up large photos) that performs the heavy lifting, like scanning and deleting files.
- Lovable chat mode: a planning step that scans code, proposes changes, and implements them.
- SQL statement/manual trigger: a direct way to test the function from the Supabase SQL editor without waiting for the cron schedule.
- Deployment: confirming the function is live before testing.
- Logs: essential to keep an eye on runs and investigate behavior.
- User photos folder: where files are stored and from which oversized files are removed.
- Five megabytes threshold: the size limit used to determine which photos to delete for storage savings.
- Every five minutes: the schedule chosen to keep storage clean regularly.
- Automation use cases: cleaning user data, sending billing notifications, and other recurring tasks that reduce manual backend work.
Have questions about setting schedules, testing with SQL, or choosing thresholds? Share your scenario and constraints to get tailored suggestions from the community.