https://github.com/codesyncr/adonis-jobs
Bull Job Wrapper for Adonis JS
https://github.com/codesyncr/adonis-jobs
Last synced: 5 months ago
JSON representation
Bull Job Wrapper for Adonis JS
- Host: GitHub
- URL: https://github.com/codesyncr/adonis-jobs
- Owner: CodeSyncr
- License: mit
- Created: 2024-09-16T18:49:37.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-14T08:50:49.000Z (over 1 year ago)
- Last Synced: 2025-09-06T00:56:33.197Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.36 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README

## What's this
`@brighthustle/adonis-jobs` is a powerful queue system designed specifically for AdonisJS applications, leveraging the reliability and scalability of BullMQ, a Redis-based queue for Node.js. Inspired from `@rocketseat/adonis-bull`, it offers enhanced functionality tailored to AdonisJS's ecosystem.
## Table of Contents
1. [Installation](#installation)
2. [Configuration](#configuration)
3. [Usage](#usage)
- [Job Dispatching](#job-dispatching)
- [Job Creation](#job-creation)
- [Job Lifecycle](#job-lifecycle)
4. [Advanced Features](#advanced-features)
- [Job Attempts and Retries](#job-attempts-and-retries)
- [Running the Queue Worker](#running-the-queue-worker)
5. [Dependencies](#dependencies)
Begin by installing `@brighthustle/adonis-jobs` using npm:
```bash
npm install @brighthustle/adonis-jobs
```
After installation, configure the package to adapt it to your AdonisJS project:
```bash
node ace configure @brighthustle/adonis-jobs
```
Utilize the `addTask` method provided by the `bull` provider to enqueue jobs.
Example:
> Please note that #app is an alia that was created by me, and isn't in adonis by default... So if you want to use it, you will need to add it in your tsconfig and package.json
```typescript
import app from '@adonisjs/core/services/app'
import queue from '@brighthustle/adonis-jobs/services/main'
```
Generate new job classes using the `node ace make:job {job}` command.
Example:
```ts
// app/jobs/register_stripe_customer.ts
import { JobHandlerContract, Job } from '@brighthustle/adonis-jobs/types'
export type RegisterStripeCustomerPayload = {
userId: string
}
export default class RegisterStripeCustomer
implements JobHandlerContract
{
public async handle(job: Job) {
// Logic to register a Stripe customer
const { userId } = job.data
// Perform Stripe registration process
}
public async failed(job: Job) {
// Logic to handle failed job attempts
const { userId } = job.data
// Send notification or log failure
}
}
```
Register the new job into `start/jobs.ts`
```ts
// start/jobs.ts
const jobs: Record = {}
export { jobs }
```
Define the `handle` method to execute job logic and the `failed` method to handle failed attempts.
- Customize the retry setting for jobs, configurable in the `config/queue.ts` file.
- Adjust attempts and delays per job or globally.
Initiate the queue worker using the `node ace queue:listen` command.
- Specify queues or run the UI for monitoring and managing queues.
- **@queuedash/api**: Provides API endpoints for monitoring and managing queues.
- **@trpc/server**: Starts QueueDash API server.
- **bullmq**: The core library for handling queues.
# Author
Kumar Yash