A lightweight SQLite-based queue system for Val Town with priority support, scheduled execution, retries, and monitoring.
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:
ProcessorMap typeprocessMyTask)processors objecttypes.tsVALID_TASK_TYPES in api.tsExample:
// 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 executionpriority and scheduled_for when selecting tasksmax_attempts timesThe /monitor endpoint returns:
README.md for detailed API referencetypes.ts for all type definitionsprocessors.ts with your own task types/monitor endpoint to track queue health