{"id":20046401,"url":"https://github.com/aneldev/dyna-queue-handler","last_synced_at":"2026-06-05T01:31:02.930Z","repository":{"id":39558853,"uuid":"100202497","full_name":"aneldev/dyna-queue-handler","owner":"aneldev","description":"Job queue that uses the disk and not the memory, for node.js services.","archived":false,"fork":false,"pushed_at":"2023-09-13T09:06:22.000Z","size":4322,"stargazers_count":0,"open_issues_count":24,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-13T07:49:41.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aneldev.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-13T20:22:19.000Z","updated_at":"2023-09-12T06:38:06.000Z","dependencies_parsed_at":"2024-11-13T11:24:02.466Z","dependency_job_id":"993e7a41-a4f1-40b7-8b99-6d69e58e9f35","html_url":"https://github.com/aneldev/dyna-queue-handler","commit_stats":null,"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-queue-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-queue-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-queue-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-queue-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aneldev","download_url":"https://codeload.github.com/aneldev/dyna-queue-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241476435,"owners_count":19968916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T11:23:36.088Z","updated_at":"2026-06-05T01:31:02.894Z","avatar_url":"https://github.com/aneldev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# DynaQueueHandler - A Utility Library for Managing Queued Jobs\n\nThe `DynaQueueHandler` class is a powerful utility library designed to help you manage queued jobs efficiently. It allows you to control the parallel execution of asynchronous tasks, making it ideal for scenarios where you need to manage concurrency and ensure job execution order.\n\n**DynaQueueHandler is a robust and widely used library in production non-public projects. It is written in TypeScript and serves as a handler for processing heavy data loads in both Node.js and web applications.**\n\n## Installation\n\nTo use `DynaQueueHandler` in your node.js or web project, you can install it via npm:\n\n```bash\nnpm install dyna-queue-handler\n```\n\n## Usage\n\n### Importing the Library\n\n```javascript\nimport { DynaQueueHandler } from \"dyna-queue-handler\";\n```\n\n### Creating an Instance\n\nTo create an instance of `DynaQueueHandler`, you need to provide a configuration object that defines the behavior of the queue handler. Here's an example of how to create an instance:\n\n```javascript\nconst queueHandler = new DynaQueueHandler({\n  parallels: 3, // Number of parallel jobs to execute (optional, defaults to 1)\n  autoStart: true, // Whether to start processing jobs automatically (optional, defaults to true)\n  onJob: async (data) =\u003e {\n    // The function to execute for each job\n    // You can define your job processing logic here\n  },\n  memorySet: async (key, data) =\u003e {\n    // Function to store data in memory\n  },\n  memoryGet: async (key) =\u003e {\n    // Function to retrieve data from memory\n  },\n  memoryDel: async (key) =\u003e {\n    // Function to delete data from memory\n  },\n  memoryDelAll: async () =\u003e {\n    // Function to delete all data from memory\n  },\n});\n```\n\nThe \"memory\" callbacks provide you with the freedom to choose the type of memory storage you want to use. With these callbacks, you can use anything from simple memory to a database. The choice is yours.\n\n### Starting and Stopping the Queue\n\nYou can start and stop the queue handler using the following methods:\n\n```javascript\nqueueHandler.start(); // Start processing jobs\nqueueHandler.stop();  // Stop processing jobs\n```\n\n### Adding Jobs to the Queue\n\nTo add a job to the queue, use the `addJob` method. You can specify the data for the job and an optional priority level:\n\n```javascript\nawait queueHandler.addJob({/* your job data */}, /* priority */);\n```\n\n### Monitoring Queue Status\n\nYou can monitor the status of the queue using the following properties and methods:\n\n- `queueHandler.isWorking`: Returns `true` if there are active jobs being processed.\n- `queueHandler.hasJobs`: Returns `true` if there are pending jobs in the queue.\n- `queueHandler.jobsCount`: Returns the total number of jobs (including processing).\n- `queueHandler.processingJobsCount`: Returns the number of currently processing jobs.\n- `queueHandler.allDone()`: Returns a promise that resolves when all jobs are completed.\n\n## Example\n\nHere's a simple example of how to use `DynaQueueHandler`:\n\n```typescript\nimport { DynaQueueHandler } from \"dyna-queue-handler\";\n\n// Define the IPerson interface\ninterface IPerson {\n  displayName: string;\n  start: number;\n}\n\n// Create a DynaQueueHandler instance with configuration\nconst queueHandler = new DynaQueueHandler\u003cIPerson\u003e({\n  parallels: 2,\n  onJob: async (data) =\u003e {\n    console.log(`Processing job for ${data.displayName} (started at ${data.start})`);\n    // Simulate job execution\n    await new Promise\u003cvoid\u003e((resolve) =\u003e setTimeout(resolve, 1000));\n  },\n  memorySet: async (key, data) =\u003e {\n    // Implement your memory set logic here\n    // For example, using an in-memory object:\n    memoryStorage[key] = data;\n  },\n  memoryGet: async (key) =\u003e {\n    // Implement your memory get logic here\n    // For example, using an in-memory object:\n    return memoryStorage[key];\n  },\n  memoryDel: async (key) =\u003e {\n    // Implement your memory delete logic here\n    // For example, using an in-memory object:\n    delete memoryStorage[key];\n  },\n  memoryDelAll: async () =\u003e {\n    // Implement your memory delete all logic here\n    // For example, using an in-memory object:\n    memoryStorage = {};\n  },\n});\n\n// Start processing jobs\nqueueHandler.start();\n\n// In-memory storage (replace with your preferred storage mechanism)\nlet memoryStorage: { [key: string]: IPerson } = {};\n\n// Add jobs to the queue\nawait queueHandler.addJob\u003cIPerson\u003e({ displayName: \"Person 1\", start: Date.now() });\nawait queueHandler.addJob\u003cIPerson\u003e({ displayName: \"Person 2\", start: Date.now() });\nawait queueHandler.addJob\u003cIPerson\u003e({ displayName: \"Person 3\", start: Date.now() });\n\n// Wait for all jobs to complete\nawait queueHandler.allDone();\n\n// Stop the queue\nqueueHandler.stop();\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faneldev%2Fdyna-queue-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faneldev%2Fdyna-queue-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faneldev%2Fdyna-queue-handler/lists"}