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 protected jobs = new Map<ID, Job>();
  protected protected unsettledJobs: { [queueName: string]: Array<{ job: Job; updatedAt: Date }> } = {};
  init(injector: Injector) => ;
  destroy() => ;
  async add(job: Job<Data>) => Promise<Job<Data>>;
  async findOne(id: ID) => Promise<Job | undefined>;
  async findMany(options?: JobListOptions) => Promise<PaginatedList<Job>>;
  async findManyById(ids: ID[]) => Promise<Job[]>;
  async next(queueName: string, waitingJobs: Job[] = []) => Promise<Job | undefined>;
  async update(job: Job) => Promise<void>;
  async removeSettledJobs(queueNames: string[] = [], olderThan?: Date) => Promise<number>;
}

Extends

Implements

Members

jobs

protected property
type:

unsettledJobs

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

init

method
type:
(injector: Injector) =>

destroy

method
type:
() =>

add

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

findOne

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

findMany

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

findManyById

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

next

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

update

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

removeSettledJobs

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