{"id":26515774,"url":"https://github.com/gotocva/queue","last_synced_at":"2026-05-15T23:37:08.864Z","repository":{"id":282401054,"uuid":"948471323","full_name":"gotocva/queue","owner":"gotocva","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-14T11:55:33.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T12:33:27.111Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/gotocva.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":"2025-03-14T11:54:21.000Z","updated_at":"2025-03-14T11:55:36.000Z","dependencies_parsed_at":"2025-03-14T12:43:45.229Z","dependency_job_id":null,"html_url":"https://github.com/gotocva/queue","commit_stats":null,"previous_names":["gotocva/queue"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotocva%2Fqueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotocva%2Fqueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotocva%2Fqueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotocva%2Fqueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gotocva","download_url":"https://codeload.github.com/gotocva/queue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244745671,"owners_count":20503051,"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":"2025-03-21T06:17:53.072Z","updated_at":"2026-05-15T23:37:03.841Z","avatar_url":"https://github.com/gotocva.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 📦 @gotocva/queue  \n**An in-memory event queue for Node.js with retry and backoff support.**  \n\n[![NPM Version](https://img.shields.io/npm/v/@gotocva/queue.svg)](https://www.npmjs.com/package/@gotocva/queue)  \n[![License](https://img.shields.io/npm/l/@gotocva/queue.svg)](https://github.com/gotocva/queue/blob/main/LICENSE)  \n[![Downloads](https://img.shields.io/npm/dt/@gotocva/queue.svg)](https://www.npmjs.com/package/@gotocva/queue)  \n\n---\n\n## 🚀 Features\n✅ **In-memory queue** (No Redis, No Database)  \n✅ **Auto-retry failed jobs** (with configurable attempts)  \n✅ **Backoff delay before retry**  \n✅ **Process jobs sequentially**  \n✅ **Simple API, Lightweight, and Fast**  \n\n---\n\n## 📥 Installation  \nInstall via **npm**:  \n```sh\nnpm install @gotocva/queue\n```\n\nInstall via **yarn**:  \n```sh\nyarn add @gotocva/queue\n```\n\n---\n\n## 📌 Usage  \n\n### 1️⃣ **Basic Example**  \n```javascript\nconst Queue = require('@gotocva/queue');\n\nconst jobQueue = new Queue();\n\n// Register event listener to process jobs\njobQueue.on('process', async (job, resolve, reject) =\u003e {\n  console.log(`Processing job: ${JSON.stringify(job)}`);\n\n  // Simulate a failing job (50% failure rate)\n  if (Math.random() \u003e 0.5) {\n    return reject(new Error('Random Job Failure'));\n  }\n\n  setTimeout(resolve, 1000); // Simulate async task success\n});\n\n// Add jobs with retry \u0026 backoff\njobQueue.add({ id: 1, task: 'Send Email' }, { attempts: 3, backoff: 5000 });\njobQueue.add({ id: 2, task: 'Generate Report' }, { attempts: 3, backoff: 5000 });\n```\n\n---\n\n## 📖 API Reference\n\n### 🏗 `new Queue()`\nCreates a new instance of the **in-memory queue**.\n\n### 📌 `.add(job, options)`\nAdds a **job** to the queue.  \n#### **Parameters**  \n- **`job`** *(Object)* → Job data (e.g., `{ id: 1, task: 'Send Email' }`)  \n- **`options`** *(Object, optional)*:  \n  - `attempts` *(Number)* → Number of times to retry on failure *(default: `3`)*\n  - `backoff` *(Number)* → Delay before retrying in **ms** *(default: `5000`)*  \n\n#### **Example**\n```javascript\nqueue.add({ id: 1, task: 'Send Email' }, { attempts: 3, backoff: 5000 });\n```\n\n---\n\n### 🔄 `.on('process', async (job, resolve, reject) =\u003e { ... })`\nRegisters a **listener** that processes jobs.\n\n#### **Parameters**\n- **`job`** *(Object)* → The job being processed  \n- **`resolve`** *(Function)* → Call this when the job succeeds  \n- **`reject`** *(Function)* → Call this when the job fails  \n\n#### **Example**\n```javascript\nqueue.on('process', async (job, resolve, reject) =\u003e {\n  try {\n    console.log(`Processing job: ${job.task}`);\n    resolve(); // Mark job as complete\n  } catch (error) {\n    reject(error); // Retry if job fails\n  }\n});\n```\n\n---\n\n## ⚡ Advanced Example\n\n### **Simulating API Calls \u0026 Retrying on Failure**\n```javascript\nconst Queue = require('@gotocva/queue');\nconst axios = require('axios');\n\nconst apiQueue = new Queue();\n\n// Process jobs (making API request)\napiQueue.on('process', async (job, resolve, reject) =\u003e {\n  console.log(`Calling API: ${job.url}`);\n\n  try {\n    const response = await axios.get(job.url);\n    console.log(`✅ API Success: ${response.status}`);\n    resolve();\n  } catch (error) {\n    console.error(`❌ API Failed: ${error.message}`);\n    reject(error);\n  }\n});\n\n// Add an API call job\napiQueue.add({ url: 'https://jsonplaceholder.typicode.com/posts/1' }, { attempts: 5, backoff: 3000 });\n```\n\n---\n\n## 🛠 How It Works  \n\n| **Step** | **Description** |\n|----------|---------------|\n| 1️⃣ | Jobs are added to the queue using `.add(job, options)`. |\n| 2️⃣ | The `process` event is triggered for each job. |\n| 3️⃣ | If the job succeeds, `resolve()` is called. |\n| 4️⃣ | If the job fails, `reject(error)` is called, and the job retries based on `attempts`. |\n| 5️⃣ | Failed jobs wait (`backoff` ms) before retrying. |\n\n---\n\n## 📌 Why Use `@gotocva/queue`?  \n\n✅ **No Dependencies** → No need for Redis or external services  \n✅ **Simple API** → Just add jobs and listen for events  \n✅ **Fast \u0026 Lightweight** → Built for high performance  \n✅ **Supports Retries** → Ensures jobs are processed reliably  \n\n---\n\n## ⚖️ Comparison with Other Queues  \n\n| Feature            | @gotocva/queue  | Bull (Redis) | Kue (Redis) |\n|--------------------|---------------|-------------|-------------|\n| **No Redis Required** | ✅ Yes  | ❌ No  | ❌ No  |\n| **Retry \u0026 Backoff** | ✅ Yes  | ✅ Yes  | ✅ Yes  |\n| **In-Memory**       | ✅ Yes  | ❌ No  | ❌ No  |\n| **Simple API**      | ✅ Yes  | ❌ Complex | ❌ Complex |\n| **Good for Small Apps** | ✅ Yes  | ❌ No | ❌ No |\n\n---\n\n## 📜 License\nThis project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.\n\n---\n\n## 👨‍💻 Author\n**gotocva** - [GitHub](https://github.com/gotocva)  \n\n---\n\n## ⭐ Support\nIf you like this project, give it a ⭐ on **[GitHub](https://github.com/gotocva/queue)**! 🚀","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotocva%2Fqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgotocva%2Fqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotocva%2Fqueue/lists"}