diff --git a/README.md b/README.md
index 8964389..b2058c2 100644
--- a/README.md
+++ b/README.md
@@ -7,13 +7,13 @@
1. [Installation](#installation)
2. [Configuration](#configuration)
3. [Usage](#usage)
- - [Job Dispatching](#job-dispatching)
- - [Job Creation](#job-creation)
- - [Job Lifecycle](#job-lifecycle)
+ - [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)
-6. [Dependencies](#dependencies)
+ - [Job Attempts and Retries](#job-attempts-and-retries)
+ - [Running the Queue Worker](#running-the-queue-worker)
+5. [Dependencies](#dependencies)
## Installation
@@ -37,59 +37,64 @@ node ace configure @acidiney/bull-queue
Utilize the `dispatch` 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 bull from '@acidiney/bull-queue/services/main'
-import RegisterStripeCustomer, { RegisterStripeCustomerPayload } from '#app/jobs/register_stripe_customer.js'
+import RegisterStripeCustomer, {
+ RegisterStripeCustomerPayload,
+} from '#app/jobs/register_stripe_customer.js'
await app.booted(async () => {
- bull.dispatch(
- RegisterStripeCustomer.name,
- { userId: '123456' } as RegisterStripeCustomerPayload,
- )
+ bull.dispatch(RegisterStripeCustomer.name, { userId: '123456' } as RegisterStripeCustomerPayload)
})
```
+
### Job Creation
Generate new job classes using the `node ace make:job {job}` command.
Example:
+
```ts
// app/jobs/register_stripe_customer.ts
-import app from '@adonisjs/core/services/app'
import { JobHandlerContract, Job } from '@acidiney/bull-queue/types'
export type RegisterStripeCustomerPayload = {
- userId: string;
-};
-
-export default class RegisterStripeCustomer implements JobHandlerContract {
+ userId: string
+}
+export default class RegisterStripeCustomer
+ implements JobHandlerContract
+{
public async handle(job: Job) {
// Logic to register a Stripe customer
- const { userId } = job.data;
+ const { userId } = job.data
// Perform Stripe registration process
}
public async failed(job: Job) {
// Logic to handle failed job attempts
- const { userId } = job.data;
+ const { userId } = job.data
// Send notification or log failure
}
}
```
Register the new job into `start/jobs.ts`
+
```ts
// start/jobs.ts
+import RegisterStripeCustomer from '#app/jobs/register_stripe_customer'
const jobs: Record = {
- () => import('#app/jobs/register_stripe_customer.js'),
+ [RegisterStripeCustomer.name]: () => import('#app/jobs/register_stripe_customer'),
}
export { jobs }
```
-
### Job Lifecycle
Define the `handle` method to execute job logic and the `failed` method to handle failed attempts.
@@ -104,9 +109,11 @@ Define the `handle` method to execute job logic and the `failed` method to handl
### Running the Queue Worker
Initiate the queue worker using the `node ace queue:listen` command.
+
- Specify queues or run the UI for monitoring and managing queues.
Example:
+
```bash
node ace queue:listen:ui
```
@@ -128,14 +135,16 @@ In case you want to start a custom queue, do not forget to name it when you `dis
```ts
import app from '@adonisjs/core/services/app'
import bull from '@acidiney/bull-queue/services/main'
-import RegisterStripeCustomer, { RegisterStripeCustomerPayload } from '#app/jobs/register_stripe_customer.js'
+import RegisterStripeCustomer, {
+ RegisterStripeCustomerPayload,
+} from '#app/jobs/register_stripe_customer.js'
await app.booted(async () => {
bull.dispatch(
RegisterStripeCustomer.name,
{ userId: '123456' } as RegisterStripeCustomerPayload,
{
- queueName: 'stripe'
+ queueName: 'stripe',
}
)
})
@@ -151,4 +160,5 @@ This command starts the queue worker and launches the UI for convenient manageme
- **h3**: A library for generating unique hash codes.
# Author
+
Acidiney Dias
diff --git a/stubs/jobs/main.stub b/stubs/jobs/main.stub
index 565c867..8b57fdf 100644
--- a/stubs/jobs/main.stub
+++ b/stubs/jobs/main.stub
@@ -8,7 +8,6 @@
})
}}}
-import app from '@adonisjs/core/services/app'
import type { JobHandlerContract, Job } from '@acidiney/bull-queue/types'
export type {{ name }}Payload = {}
@@ -18,10 +17,14 @@ export default class {{ name }}Job implements JobHandlerContract<{{ name }}Paylo
/**
* Base Entry point
*/
- async handle(job: Job<{{ name }}Payload>) {}
+ async handle(job: Job<{{ name }}Payload>) {
+ throw new Error("Need to be implemented!")
+ }
/**
* This is an optional method that gets called if it exists when the retries has exceeded and is marked failed.
*/
- async failed() {}
+ async failed()job: Job<{{ name }}Payload>) {
+ throw new Error("Need to be implemented!")
+ }
}