{"id":26601641,"url":"https://github.com/aaronjan/stanchionjs","last_synced_at":"2025-04-09T16:37:04.601Z","repository":{"id":57369314,"uuid":"100483361","full_name":"AaronJan/StanchionJS","owner":"AaronJan","description":"A simple \u0026 fast queue done right. backed by Redis, supports auto-reconnect, TypeScript, Promise and Rxjs.","archived":false,"fork":false,"pushed_at":"2018-02-05T08:22:19.000Z","size":26,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T09:04:03.532Z","etag":null,"topics":["nodejs","queue","redis","rxjs","rxjs5","simple","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/AaronJan/StanchionJS","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AaronJan.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}},"created_at":"2017-08-16T11:46:25.000Z","updated_at":"2019-11-01T16:18:34.000Z","dependencies_parsed_at":"2022-09-03T19:01:18.677Z","dependency_job_id":null,"html_url":"https://github.com/AaronJan/StanchionJS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AaronJan%2FStanchionJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AaronJan%2FStanchionJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AaronJan%2FStanchionJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AaronJan%2FStanchionJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AaronJan","download_url":"https://codeload.github.com/AaronJan/StanchionJS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248068448,"owners_count":21042493,"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":["nodejs","queue","redis","rxjs","rxjs5","simple","typescript"],"created_at":"2025-03-23T18:41:03.325Z","updated_at":"2025-04-09T16:37:04.575Z","avatar_url":"https://github.com/AaronJan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=center\u003e\n    \u003cimg alt=\"StanchionJS\" src=\"https://aaronjan.github.io/StanchionJS/docs/logo-by-freepik.png\"\u003e\n    \u003cbr\u003e\n    StanchionJS\n\u003c/h1\u003e\n\n\n\u003cp align=center\u003e\n\u003ca href=\"https://www.npmjs.com/package/stanchionjs\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/stanchionjs.svg?style=flat\" alt=\"npm version\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\nA simple \u0026 fast queue done right. backed by Redis, supports auto-reconnect, TypeScript, Promise and Rxjs.\n\n\n## Features\n\n- **Fast.** Just `BLPOP` and `RPUSH`, no other fancy stuff, simple and fast.\n\n- **Auto-Reconnect.**\n\n- **Works with Promise.** Unleash the power of `async / await`, say bye-bye to callback.\n\n- **Better error handling.**\n\n- **Written in TypeScript.** No hacky code and provides better experience if you are using `TypeScript`.\n\n- **Reactive.** If you don't like making promises, there're reactive APIs too, all APIs have two versions.\n\n\n## Installation\n\n```\n$ npm i stanchionjs\n```\n\n\n## Examples\n\n### Initialize\n\n```javascript\nconst { Stanchion } = require('stanchionjs');\n\nconst stanchion = new Stanchion({\n    redis: {\n        host: '127.0.0.1',\n        port: 6379,\n        db: '1',\n    },\n    concurrency: 20,\n});\n\n```\n\n\n### How To Create a Job\n\n```javascript\nconst { Stanchion } = require('stanchionjs');\n\nconst stanchion = new Stanchion();\n\n// Payload will be serialized using `JSON.stringify`\nconst job_1 = {\n    thing: 'apple',\n};\nconst job_2 = {\n    thing: 'banana',\n};\n\n//\n// Promise way:\n//\n\nstanchion.push(job_1, job_2).then(() =\u003e {\n    console.log('jobs created.');\n});\n\n//\n// Rxjs way:\n//\n\nstanchion.push$(job_1, job_2).subscribe(() =\u003e {\n    console.log('jobs created.');\n});\n\n```\n\n\n### How To Process a Job\n\nWhen a Job processing is done, you must tell `StanchionJS` so it can go fetching next Job for you. `StanchionJS` provides several ways to do that:\n\n```javascript\nconst { Stanchion } = require('stanchionjs');\nconst { Observable } = require('rxjs'); // Not required.\n\nconst stanchion = new Stanchion();\n\n//\n// Promise way:\n//\n\nstanchion.process(job =\u003e new Promise((resolve, reject) =\u003e {\n    console.log('Got a job:', job);\n\n    resolve();\n}));\n\n//\n// Async / Await way:\n//\n\nstanchion.process(async job =\u003e {\n    console.log('Got a job:', job);\n});\n\n//\n// Rxjs way:\n//\n\nstanchion.process$(\n    job =\u003e Observable.of(job)\n        .map(job =\u003e {\n            console.log('Got a job:', job);\n        })\n).subscribe(); // Don't forget to subscribe!\n\n```\n\n\n### Error Handling\n\nEvery exception (including those from `redis`) can be obtained by attach handler to `Stanchion` instance:\n\n```javascript\nconst { Stanchion } = require('stanchionjs');\n\nconst stanchion = new Stanchion();\n\n//\n// Callback handler:\n//\n\nstanchion.onError(err =\u003e {\n    console.log('error occurred', err);\n});\n\n//\n// Rxjs stream:\n//\n\nstanchion.onError$().subscribe(err =\u003e {\n    console.log('error occurred', err);\n});\n\n```\n\n\n### How To Exit\n\n```javascript\nconst { Stanchion } = require('stanchionjs');\n\nconst stanchion = new Stanchion();\n\n//\n// Promise way:\n//\n\nstanchion.shutdown().then(() =\u003e {\n    console.log('Stanchion exited.');\n});\n\n//\n// Rxjs way:\n//\n\nstanchion.shutdown$().subscribe(() =\u003e {\n    console.log('Stanchion exited.');\n});\n\n```\n\n\n### When Exited\n\n```javascript\nconst { Stanchion } = require('stanchionjs');\n\nconst stanchion = new Stanchion();\n\n//\n// Promise way:\n//\n\nstanchion.onShutdowned(() =\u003e {\n    console.log('Stanchion exited.');\n});\n\n//\n// Rxjs way:\n//\n\nstanchion.onShutdowned$().subscribe(() =\u003e {\n    console.log('Stanchion exited.');\n});\n\n```\n\n\n## Reference\n\n### Interfaces\n\n#### ConstructOptions\n\nDefault value:\n\n```javascript\n{\n    // Redis configuration.\n    redis: {\n        host: '127.0.0.1',\n        port: 6739,\n    },\n\n    // If you have lots of I/O intensive jobs, increase this may help.\n    concurrency: 10,\n    \n    // Redis key for this queue.\n    // Stanchion also support multiple keys, just use:\n    //   rediskey: ['stanchion_queue1', 'stanchion_queue2']\n    redisKey: 'stanchion_queue',\n    \n    // How many times you want Stanchion to try reconnecting when connection is lost.\n    retryAttempts: 6,\n}\n```\n\n\n### Stanchion\n\n#### Stanchion#constructor\n\n```typescript\nconstructor(options: ConstructOptions)\n```\n\n#### Stanchion#push\n\n```typescript\npush(...jobs: any[]): Promise\u003cvoid\u003e\n```\n\n#### Stanchion#push$\n\n```typescript\npush$(...jobs: any[]): Observable\u003cvoid\u003e\n```\n\n#### Stanchion#getSize\n\n```typescript\ngetSize(): Promise\u003cnumber\u003e\n```\n\n#### Stanchion#getSize$\n\n```typescript\ngetSize$(): Observable\u003cnumber\u003e\n```\n\n#### Stanchion#onError\n\n```typescript\nonError(handler: ErrorHandler): Subscription\n```\n\n#### Stanchion#onError$\n\n```typescript\nonError$(): Subject\u003cany\u003e\n```\n\n#### Stanchion#process\n\n```typescript\nprocess(processor: PromiseProcessor): Promise\u003cvoid\u003e\n```\n\n#### Stanchion#process$\n\n```typescript\nprocess$(processor: ObservableProcessor): Observable\u003cvoid\u003e\n```\n\n#### Stanchion#shutdown\n\n```typescript\nshutdown(): Promise\u003cvoid\u003e\n```\n\n#### Stanchion#shutdown$\n\n```typescript\nshutdown$(): Observable\u003cvoid\u003e\n```\n\n#### Stanchion#isShutdowned\n\n```typescript\nisShutdowned(): boolean\n```\n\n#### Stanchion#onShutdowned\n\n```typescript\nonShutdowned(cb: VoidFunction): Subscription\n```\n\n#### Stanchion#onShutdowned$\n\n```typescript\nonShutdowned$(): Observable\u003cvoid\u003e\n```\n\n\n## TODOs\n\n- Tests. Although Stanchion is bettle-tested, handling about 26K jobs per second.\n\n- Multiple queue (Redis key) support.\n\n- \"unprocess\" method.\n\n- Key-sharding support for cluster usage.\n\n\n## Credits\n\nAwesome icon by [Freepik](http://www.freepik.com), licensed under the [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/).\n\nInspired by [Neamar/featureless-job-queue](https://github.com/Neamar/featureless-job-queue).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronjan%2Fstanchionjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronjan%2Fstanchionjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronjan%2Fstanchionjs/lists"}