Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stanchionjs

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stanchionjs - npm Package Compare versions

Comparing version 0.9.1 to 1.0.0

2

package.json
{
"name": "stanchionjs",
"version": "0.9.1",
"version": "1.0.0",
"description": "A simple & fast queue done right. backed by Redis, supports auto-reconnect, TypeScript, Promise and Rxjs.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -13,4 +13,2 @@ <h1 align=center>

**[Work in progress]**
A simple & fast queue done right. backed by Redis, supports auto-reconnect, TypeScript, Promise and Rxjs.

@@ -31,3 +29,3 @@

- **Reactive.** If you don't like making promises, there're reactive APIs too.
- **Reactive.** If you don't like making promises, there're reactive APIs too, all APIs have two versions.

@@ -44,5 +42,294 @@

TODO
### Initialize
```javascript
const { Stanchion } = require('stanchionjs');
const stanchion = new Stanchion({
redis: {
host: '127.0.0.1',
port: 6379,
db: '1',
},
concurrency: 20,
});
```
### How To Create a Job
```javascript
const { Stanchion } = require('stanchionjs');
const stanchion = new Stanchion();
// Payload will be serialized using `JSON.stringify`
const job_1 = {
thing: 'apple',
};
const job_2 = {
thing: 'banana',
};
//
// Promise way:
//
stanchion.push(job_1, job_2).then(() => {
console.log('jobs created.');
});
//
// Rxjs way:
//
stanchion.push$(job_1, job_2).subscribe(() => {
console.log('jobs created.');
});
```
### How To Process a Job
When 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:
```javascript
const { Stanchion } = require('stanchionjs');
const { Observable } = require('rxjs'); // Not required.
const stanchion = new Stanchion();
//
// Promise way:
//
stanchion.process(job => new Promise((resolve, reject) => {
console.log('Got a job:', job);
resolve();
}));
//
// Async / Await way:
//
stanchion.process(async job => {
console.log('Got a job:', job);
});
//
// Rxjs way:
//
stanchion.process$(
job => Observable.of(job)
.map(job => {
console.log('Got a job:', job);
})
).subscribe(); // Don't forget to subscribe!
```
### Error Handling
Every exception (including those from `redis`) can be obtained by attach handler to `Stanchion` instance:
```javascript
const { Stanchion } = require('stanchionjs');
const stanchion = new Stanchion();
//
// Callback handler:
//
stanchion.onError(err => {
console.log('error occurred', err);
});
//
// Rxjs stream:
//
stanchion.onError$().subscribe(err => {
console.log('error occurred', err);
});
```
### How To Exit
```javascript
const { Stanchion } = require('stanchionjs');
const stanchion = new Stanchion();
//
// Promise way:
//
stanchion.shutdown().then(() => {
console.log('Stanchion exited.');
});
//
// Rxjs way:
//
stanchion.shutdown$().subscribe(() => {
console.log('Stanchion exited.');
});
```
### When Exited
```javascript
const { Stanchion } = require('stanchionjs');
const stanchion = new Stanchion();
//
// Promise way:
//
stanchion.onShutdowned(() => {
console.log('Stanchion exited.');
});
//
// Rxjs way:
//
stanchion.onShutdowned$().subscribe(() => {
console.log('Stanchion exited.');
});
```
## Reference
### Interfaces
#### ConstructOptions
Default value:
```javascript
{
// Redis configuration.
redis: {
host: '127.0.0.1',
port: 6739,
},
// If you have lots of I/O intensive job, increase this may help.
concurrency: 10,
// `concurrency` * `prefetchRatio` = how many Redis command will be emitted.
prefetchRatio: 1.2,
// Redis key for this queue.
redisKey: 'stanchion:queue',
// How many times you want Stanchion to reconnecting when connection lost.
retryAttempts: 6,
}
```
### Stanchion
#### Stanchion#constructor
```typescript
constructor(options: ConstructOptions)
```
#### Stanchion#push
```typescript
push(...jobs: any[]): Promise<void>
```
#### Stanchion#push$
```typescript
push$(...jobs: any[]): Observable<void>
```
#### Stanchion#getSize
```typescript
getSize(): Promise<number>
```
#### Stanchion#getSize$
```typescript
getSize$(): Observable<number>
```
#### Stanchion#onError
```typescript
onError(handler: ErrorHandler): Subscription
```
#### Stanchion#onError$
```typescript
onError$(): Subject<any>
```
#### Stanchion#process
```typescript
process(processor: PromiseProcessor): Promise<void>
```
#### Stanchion#process$
```typescript
process$(processor: ObservableProcessor): Observable<void>
```
#### Stanchion#shutdown
```typescript
shutdown(): Promise<void>
```
#### Stanchion#shutdown$
```typescript
shutdown$(): Observable<void>
```
#### Stanchion#isShutdowned
```typescript
isShutdowned(): boolean
```
#### Stanchion#onShutdowned
```typescript
onShutdowned(cb: VoidFunction): Subscription
```
#### Stanchion#onShutdowned$
```typescript
onShutdowned$(): Observable<void>
```
## TODOs
- Tests.
## Credits

@@ -49,0 +336,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc