JobBufferStorageStrategy
JobBufferStorageStrategy
This strategy defines where to store jobs that have been collected by a JobBuffer.
Signature
interface JobBufferStorageStrategy extends InjectableStrategy {
add(bufferId: string, job: Job): Promise<Job>;
bufferSize(bufferIds?: string[]): Promise<{ [bufferId: string]: number }>;
flush(bufferIds?: string[]): Promise<{ [bufferId: string]: Job[] }>;
}
Extends
Members
add
Persist a job to the storage medium. The storage format should
take into account the
bufferId
argument, as it is necessary to be
able to later retrieve jobs by that id.
bufferSize
method
type:
(bufferIds?: string[]) => Promise<{ [bufferId: string]: number }>
Returns an object containing the number of buffered jobs arranged by bufferId.
Passing bufferIds limits the results to the specified bufferIds. If the array is empty, sizes will be returned for all bufferIds.
Example
const sizes = await myJobBufferStrategy.bufferSize(['buffer-1', 'buffer-2']);
// sizes = { 'buffer-1': 12, 'buffer-2': 3 }
flush
method
type:
(bufferIds?: string[]) => Promise<{ [bufferId: string]: Job[] }>
Clears all jobs from the storage medium which match the specified bufferIds (if the array is empty, clear for all bufferIds), and returns those jobs in an object arranged by bufferId
Example
const result = await myJobBufferStrategy.flush(['buffer-1', 'buffer-2']);
// result = {
// 'buffer-1': [Job, Job, Job, ...],
// 'buffer-2': [Job, Job, Job, ...],
// };