Async job processing for Google Antigravity IDE
# Background Jobs Guide for Google Antigravity
Master background job processing in Google Antigravity IDE. This guide covers job queues, scheduling, and retry patterns.
## BullMQ Setup
```typescript
import { Queue, Worker, Job } from "bullmq";
import Redis from "ioredis";
const connection = new Redis(process.env.REDIS_URL);
export const emailQueue = new Queue("emails", { connection });
export const emailWorker = new Worker(
"emails",
async (job: Job) => {
const { to, subject, body } = job.data;
await sendEmail(to, subject, body);
return { sent: true };
},
{
connection,
concurrency: 5,
limiter: { max: 100, duration: 60000 }
}
);
emailWorker.on("completed", (job) => {
console.log(`Job ${job.id} completed`);
});
emailWorker.on("failed", (job, err) => {
console.error(`Job ${job?.id} failed:`, err);
});
```
## Adding Jobs
```typescript
export async function queueWelcomeEmail(userId: string, email: string) {
await emailQueue.add(
"welcome-email",
{ to: email, subject: "Welcome!", userId },
{
attempts: 3,
backoff: { type: "exponential", delay: 1000 },
removeOnComplete: 100,
removeOnFail: 1000
}
);
}
// Delayed job
await emailQueue.add(
"reminder",
{ to: email, subject: "Reminder" },
{ delay: 24 * 60 * 60 * 1000 } // 24 hours
);
// Scheduled/recurring job
await emailQueue.add(
"daily-digest",
{ type: "digest" },
{ repeat: { pattern: "0 9 * * *" } } // 9 AM daily
);
```
## Job Patterns
```typescript
// Batch processing
const jobs = users.map((user) => ({
name: "process-user",
data: { userId: user.id },
opts: { priority: user.isPremium ? 1 : 10 }
}));
await queue.addBulk(jobs);
// Job dependencies
const parentJob = await queue.add("parent", { step: 1 });
await queue.add("child", { step: 2 }, { parent: { id: parentJob.id } });
```
## Best Practices
1. **Idempotent jobs** - Safe to retry
2. **Exponential backoff** - Handle transient failures
3. **Dead letter queue** - Capture failed jobs
Google Antigravity IDE provides job queue scaffolding.This Background Jobs prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their background jobs implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For Background Jobs projects, consider mentioning your framework version, coding style, and any specific libraries you're using.