BackIntegrations and automations
Integrations and automations

Automations, Scheduled Jobs, and Background Work in Blanca's Builder

Learn how to schedule recurring tasks using pg_cron or external schedulers for /api/public/* endpoints and manage background work within Blanca's Builder.

In modern web applications, automating recurring tasks and handling background processes efficiently is crucial for performance and user experience. Blanca's Builder provides robust mechanisms to manage scheduled jobs and background work, ensuring your applications run smoothly and respond quickly. This article explores how to implement these automations effectively within your projects.

Last updated: 2026-06-28

Understanding Automations and Scheduled Jobs

Automations refer to tasks that run without direct user interaction, often on a predefined schedule. Common use cases include generating daily reports, sending weekly newsletters, cleaning up old data, or synchronizing information with external services. In Blanca's Builder, these tasks can range from simple data operations to complex multi-step workflows.

Scheduled jobs are a specific type of automation that executes at predetermined times or intervals. These are essential for maintaining and enhancing your application's functionality without requiring manual intervention. Choosing the right scheduling mechanism depends on the complexity of your task and your specific infrastructure needs.

Scheduling with pg_cron for Database-Centric Tasks

For tasks that are primarily database-centric, such as aggregating data, performing periodic cleanups, or updating derived tables, Blanca's Builder leverages PostgreSQL's powerful pg_cron extension. pg_cron allows you to schedule SQL commands or functions directly within your database, using a familiar cron-like syntax. This approach is highly efficient as it minimizes network overhead and keeps the logic close to the data.

To use pg_cron, you define your scheduled tasks as standard SQL queries or PL/pgSQL functions. For example, you might schedule a function to run nightly that archives old user logs. These tasks can be configured to interact with your application's data models seamlessly, providing a robust and integrated solution for database automations. Ensure your pg_cron jobs are idempotent where possible, meaning they can be run multiple times without causing unintended side effects.

External Schedulers for Comprehensive API Workflows

When your automation needs extend beyond database operations to involve complex business logic, third-party integrations, or external services, external schedulers are the ideal choice. These schedulers can call any publicly accessible endpoint of your Blanca's Builder application, typically through the `/api/public/*` routes. Tools like Zapier, Make (formerly Integromat), AWS EventBridge, or even custom server-side cron jobs can be configured to trigger specific API endpoints.

This method offers immense flexibility, allowing you to orchestrate workflows that span multiple services, process data asynchronously, or interact with external APIs. For instance, you could schedule an external job to call an `/api/public/process_orders` endpoint nightly, which then retrieves new orders, processes payments via a third-party gateway, and sends confirmation emails. Remember to secure your external API endpoints appropriately, e.g., using API keys or webhook secrets, to prevent unauthorized access.

Handling Background Work with Server Functions

Beyond scheduled tasks, many applications require processing that can run asynchronously in the background without blocking the user interface. Blanca's Builder's server functions are well-suited for this. When a user action triggers a computationally intensive process – like generating a large report, sending multiple notifications, or resizing high-resolution images – it's best to offload this work to a background process.

Server functions allow you to execute code that doesn't immediately return a response to the client. This keeps your user interface responsive and prevents timeouts for long-running operations. You can implement patterns like 'fire and forget' or use callbacks/webhooks to notify the client when the background task is complete. While server functions handle background tasks, very high-volume or long-running computations may benefit from dedicated worker services.

When to Escalate to a Dedicated Worker

While pg_cron, external schedulers, and Blanca's Builder's server functions cover a broad range of automation and background processing needs, there are scenarios where a dedicated worker service becomes beneficial. These scenarios typically involve extremely high-volume tasks, processes requiring specific computing resources (e.g., GPU processing), or tasks that need to run continuously for extended periods (e.g., real-time data processing streams).

A dedicated worker is an independent service optimized for specific types of background work. It operates outside the primary application server, providing better scalability, fault tolerance, and resource isolation. If your application starts experiencing performance bottlenecks due to background processing, or if you need advanced queuing, retry, or monitoring capabilities beyond what the built-in solutions offer, consulting Blanca's Builder support for integrating dedicated workers would be the next logical step. This ensures your application can scale effectively and maintain optimal performance under heavy load.

Canonical: https://blancasbuilder.com/knowledge/integrations-and-automations/automations-and-cron-jobs · Blanca's Builder