Public
Like
lightweightQueue
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v75View latest version
A lightweight SQLite-based queue system for Val Town with priority support, scheduled execution, retries, and monitoring.
- ✅ SQLite-backed task queue with ACID guarantees
- ✅ Priority-based processing
- ✅ Delayed/scheduled task execution
- ✅ Automatic retry logic with configurable max attempts
- ✅ Dead letter queue for failed tasks
- ✅ Worker processing tasks every minute
- ✅ Built-in monitoring endpoint
curl https://lqw.web.val.run/schema
This creates the queue and dead_letter_queue tables.
curl -X POST https://lqw.web.val.run/enqueue \ -H "Content-Type: application/json" \ -d '{ "task_type": "log_message", "payload": { "message": "Hello from the queue!", "level": "info" } }'
Response:
{ "success": true, "task_id": "1", "status": "queued", "scheduled_for": null }
curl https://lqw.web.val.run/monitor
View stats on task counts, processing durations, dead letter queue, and upcoming scheduled tasks.
| Type | Purpose | Payload |
|---|---|---|
| log_message | Log to console | { message: string, level: "info" | "warning" | "error" } |
| send_email | Send email via Val Town | { to: string, subject: string, text: string } |
| webhook | POST to an external URL | { url: string, method?: string, body?: any, headers?: object } |
| http_request | Make HTTP requests | { url: string, method?: string, body?: any, headers?: object } |
curl -X POST https://lqw.web.val.run/enqueue \ -H "Content-Type: application/json" \ -d '{ "task_type": "log_message", "payload": { "message": "Urgent!", "level": "info" }, "priority": 10 }'
curl -X POST https://lqw.web.val.run/enqueue \ -H "Content-Type: application/json" \ -d '{ "task_type": "log_message", "payload": { "message": "See you later!", "level": "info" }, "scheduled_for": '$(date -v+1H +%s)' }'
curl -X POST https://lqw.web.val.run/enqueue \ -H "Content-Type: application/json" \ -d '{ "task_type": "send_email", "payload": { "to": "user@example.com", "subject": "Queue Test", "text": "Hello from the queue!" } }'
curl -X POST https://lqw.web.val.run/enqueue \ -H "Content-Type: application/json" \ -d '{ "task_type": "webhook", "payload": { "url": "https://example.com/webhook", "method": "POST", "body": { "event": "task_completed" } } }'
| File | Purpose |
|---|---|
api.ts | HTTP endpoints (/schema, /enqueue, /monitor) |
schema.ts | Database schema initialization |
types.ts | TypeScript types and Zod schemas |
processors.ts | Task execution logic for each task type |
worker.ts | Cron that processes queued tasks |
Add a new task type in processors.ts:
- Add to the
ProcessorMaptype - Create a processor function (e.g.,
processMyTask) - Add it to the
processorsobject - Add a Zod schema to
types.ts - Update
VALID_TASK_TYPESinapi.ts
Example:
// In processors.ts
async function processMyTask(payload: MyTaskPayload) {
// Your logic here
}
// Add to ProcessorMap type and processors object
const processors = {
// ... existing
my_task: processMyTask,
};
task_type(required): One of the valid task typespayload(required): Task-specific datapriority(optional, default: 0): Higher = processed firstmax_attempts(optional, default: 3): Retries before DLQscheduled_for(optional): Unix timestamp for delayed execution
- Processes up to 10 tasks per worker run
- Runs every minute (configure in Val Town)
- Respects
priorityandscheduled_forwhen selecting tasks - Automatically retries failed tasks up to
max_attemptstimes - Moves tasks to dead letter queue after max retries
The /monitor endpoint returns:
- Task counts by status (pending, processing, completed, failed)
- Average processing duration per status
- Breakdown by task type
- Dead letter queue count and recent failures
- Upcoming scheduled tasks
- Read the full
README.mdfor detailed API reference - Check
types.tsfor all type definitions - Customize
processors.tswith your own task types - Use the
/monitorendpoint to track queue health