
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
nestjs-agenda-module
Advanced tools
A progressive Node.js framework for building efficient and scalable server-side applications.
$ npm i --save nestjs-agenda-module agenda
Once the installation process is complete, we can import the AgendaModule into the root AppModule.
//app.module.ts
import { Module } from '@nestjs/common';
import { AgendaModule } from 'nestjs-agenda-module';
@Module({
imports: [
AgendaModule.forRoot({
db: { address: 'MONGO_CONNECTION_URI' },
}),
],
})
export class AppModule {}
Before you can use a job, you must define its processing behavior.
For do this you need create processors-definer
//example.processors-definer.ts
import { ProcessorsDefiner } from 'nestjs-agenda-module';
@ProcessorsDefiner()
export class ExampleProcessorsDefiner {}
And then you can define processor
with special decorator
@Processor(jobName, [options])
//example.processors-definer.ts
import { ProcessorsDefiner, Processor } from 'nestjs-agenda-module';
@ProcessorsDefiner()
export class ExampleProcessorsDefiner {
@Processor("EXAMPLE_JOB")
public async exampleJob() {}
}
Also you can get access to current job
data or done
function with job context
//example.processors-definer.ts
import { Job } from 'agenda';
import {
ProcessorsDefiner,
Processor,
Context,
JobContext
} from 'nestjs-agenda-module';
interface ExampleJobData {
message: string;
}
@ProcessorsDefiner()
export class ExampleProcessorsDefiner {
@Processor('EXAMPLE_JOB')
public async exampleJob(
@Context() context: JobContext<ExampleJobData>,
) {
const job: Job<ExampleJobData> = context.job;
const done: Function = context.done;
console.log(job.attrs.data.message);
done();
}
}
//app.module.ts
import { Module } from '@nestjs/common';
import { AgendaModule } from 'nestjs-agenda-module';
import { ExampleProcessorsDefiner } from './example.processors-definer.ts';
@Module({
imports: [
AgendaModule.forRoot({
db: { address: 'MONGO_CONNECTION_URI' },
}),
],
providers: [ExampleProcessorsDefiner],
})
export class AppModule {}
//example.service.ts
import { Inject, Injectable } from '@nestjs/common';
import { Agenda } from 'agenda';
import { InjectAgenda } from 'nestjs-agenda-module';
@Injectable()
export class ExampleService {
public constructor(
@InjectAgenda()
private readonly agenda: Agenda,
) {}
public async createJob(): Promise<void> {
this.agenda.every('15 minutes', 'EXAMPLE_JOB', { message: 'text' }, { skipImmediate: true });
this.agenda.schedule('1 day', 'EXAMPLE_JOB', { message: 'text' });
this.agenda.now('EXAMPLE_JOB', { message: 'text' });
//etc
}
}
You have every
schedule
and now
decorators who provided default agenda behavior for create job. You can provide default data or job options like in default agenda. Just read documentation
//example.processors-definer.ts
import {
ProcessorsDefiner,
Processor,
Context,
JobContext,
Now,
Schedule,
Every,
} from 'nestjs-agenda-module';
@ProcessorsDefiner()
export class ExampleProcessorsDefiner {
@Processor('EXAMPLE_JOB_1')
@Every('15 minutes', { skipImmediate: true }, { message: 'test' })
public async exampleJob1(@Context() context: JobContext) {
done();
}
@Processor('EXAMPLE_JOB_2')
@Schedule('tomorrow at noon', { message: 'test' })
public async exampleJob2(@Context() context: JobContext) {
done();
}
@Processor('EXAMPLE_JOB_3')
@Now({ message: 'test' })
public async exampleJob3(@Context() context: JobContext) {
done();
}
}
FAQs
Agenda module for NestJs
The npm package nestjs-agenda-module receives a total of 19 weekly downloads. As such, nestjs-agenda-module popularity was classified as not popular.
We found that nestjs-agenda-module demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.