queue-manager-pro
Version:
A flexible, TypeScript-first queue/task manager with pluggable backends ,dynamic persistence storage and event hooks.
37 lines • 1.21 kB
JavaScript
import { BaseQueueRepository } from './base.repository.js';
export class MemoryQueueRepository extends BaseQueueRepository {
tasks = [];
constructor(maxRetries, maxProcessingTime) {
super(maxRetries, maxProcessingTime);
}
async deleteTask(id, hardDelete) {
const index = this.tasks.findIndex(task => task.id === id);
if (index === -1)
return undefined;
const deletedTask = this.tasks[index];
if (hardDelete) {
this.tasks.splice(index, 1);
}
else if (deletedTask) {
deletedTask.status = 'deleted';
}
return deletedTask;
}
// Storage-specific: return all tasks, optionally filter by status
async loadTasks(status) {
if (status) {
return this.tasks.filter(t => t.status === status);
}
return this.tasks;
}
// Storage-specific: replace all tasks (ignore status param for memory)
async saveTasks(tasks, _status) {
this.tasks = tasks;
return tasks;
}
// Storage-specific: push a new task into memory
async enqueue(task) {
this.tasks.push(task);
}
}
//# sourceMappingURL=memory.repository.js.map