Skip to main content

InMemoryJobQueueStrategy

InMemoryJobQueueStrategy

An in-memory JobQueueStrategy. This is the default strategy if not using a dedicated JobQueue plugin (e.g. DefaultJobQueuePlugin). Not recommended for production, since the queue will be cleared when the server stops, and can only be used when the JobQueueService is started from the main server process:

Example

bootstrap(config)
.then(app => app.get(JobQueueService).start());

Attempting to use this strategy when running the worker in a separate process (using bootstrapWorker()) will result in an error on startup.

Completed jobs will be evicted from the store every 2 hours to prevent a memory leak.

Signature
class InMemoryJobQueueStrategy extends PollingJobQueueStrategy implements InspectableJobQueueStrategy {
protected jobs = new Map<ID, Job>();
protected unsettledJobs: { [queueName: string]: Array<{ job: Job; updatedAt: Date }> } = {};
init(injector: Injector) => ;
destroy() => ;
add(job: Job<Data>) => Promise<Job<Data>>;
findOne(id: ID) => Promise<Job | undefined>;
findMany(options?: JobListOptions) => Promise<PaginatedList<Job>>;
findManyById(ids: ID[]) => Promise<Job[]>;
next(queueName: string, waitingJobs: Job[] = []) => Promise<Job | undefined>;
update(job: Job) => Promise<void>;
removeSettledJobs(queueNames: string[] = [], olderThan?: Date) => Promise<number>;
}

jobs

property

unsettledJobs

property
{ [queueName: string]: Array<{ job: Job; updatedAt: Date }> }

init

method
(injector: Injector) =>

destroy

method
() =>

add

method
(job: Job<Data>) => Promise<Job<Data>>

findOne

method
(id: ID) => Promise<Job | undefined>

findMany

method
(options?: JobListOptions) => Promise<PaginatedList<Job>>

findManyById

method
(ids: ID[]) => Promise<Job[]>

next

method
(queueName: string, waitingJobs: Job[] = []) => Promise<Job | undefined>

update

method
(job: Job) => Promise<void>

removeSettledJobs

method
(queueNames: string[] = [], olderThan?: Date) => Promise<number>