Task
This content is for the 0.6.3 version. Switch to the latest version for up-to-date documentation.
Tasks enable scheduled background job execution in Raindrop applications. They use standard Unix cron expressions to define when code should run automatically.
Each Task executes at the times specified by its cron schedule. When a Task execution fails, there’s no automatic retry mechanism. The Task will run again at the next scheduled time. Tasks have a maximum execution time of 5 minutes (300,000ms CPU walltime).
Tasks provide a reliable way to run maintenance operations, data processing, or periodic updates without manual intervention.
Creating
Configure a Task in your raindrop.manifest
file with a cron expression:
application "demo-app" { task "demo-task" { type = "cron" cron = "0 2 * * *" # Daily at 2 AM UTC }}
Accessing
Access your Task through environment bindings in your service code:
import { Task, Event } from 'raindrop';
export default class DemoTask extends Task<Env> { async handle(event: Event): Promise<void> { // Task execution logic here console.log(`Task executed at ${new Date(event.scheduledTime)}`); }}
Core Concepts
Main Interfaces
Task<Env>
- Abstract base class for processing scheduled eventsEvent
- Represents scheduled event data with timing information
Data Types
Event
interface Event { /** The value of the Cron Trigger that started the ScheduledEvent */ cron: string; /** The type of event. This will always return "scheduled" */ type: 'scheduled'; /** The time the ScheduledEvent was scheduled to be executed in milliseconds since January 1, 1970, UTC */ scheduledTime: number;}
Task
abstract class Task<Env> { ctx: ExecutionContext; // Runtime execution context env: Env; // Environment bindings
abstract handle(event: Event): Promise<void>; // Required implementation method}
System Limits
- Maximum execution time: 300,000ms (5 minutes) CPU walltime
- No automatic retry mechanism on failures
handle
event: Event // Scheduled event information
Promise<void> // Async completion
Example
Process scheduled events with timing information:
export default class BackupTask extends Task<Env> { async handle(event: Event): Promise<void> { // Log execution details const executionTime = new Date(event.scheduledTime); console.log(`Backup started at ${executionTime}`);
// Perform backup operations await this.performBackup(); }
private async performBackup(): Promise<void> { // Backup implementation }}