New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nats-jobs

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nats-jobs - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# 0.4.0
* `repeatAfter` defaults to `numEntries` for `expBackoff` util fn.
# 0.3.0

@@ -2,0 +6,0 @@

4

dist/jobProcessor.d.ts
import { ConnectionOptions } from 'nats';
import { JobDef } from './types';
/**
* Start processing jobs based on def. To gracefully shutdown
* see stop method.
* Call `start` to begin processing jobs based on def. To
* gracefully shutdown call `stop` method.
*/

@@ -7,0 +7,0 @@ export declare const jobProcessor: (opts?: ConnectionOptions | undefined) => Promise<{

@@ -74,4 +74,4 @@ "use strict";

/**
* Start processing jobs based on def. To gracefully shutdown
* see stop method.
* Call `start` to begin processing jobs based on def. To
* gracefully shutdown call `stop` method.
*/

@@ -104,3 +104,3 @@ const jobProcessor = async (opts) => {

const ps = await createConsumer(conn, def);
// Get consumer info
// Get ack wait time
const ackWait = consumerDefaults(def).ack_wait;

@@ -107,0 +107,0 @@ // Pull messages from the consumer

@@ -24,1 +24,5 @@ import { ConsumerConfig, JsMsg, StreamConfig, JetStreamClient } from 'nats';

export declare type StopFn = () => Promise<void>;
export interface BackoffOptions {
numEntries?: number;
repeatAfter?: number;
}

@@ -1,2 +0,2 @@

import { Deferred } from './types';
import { BackoffOptions, Deferred } from './types';
import { JsMsg, Nanos } from 'nats';

@@ -9,7 +9,7 @@ export declare const nanos: (x: string) => number;

* `repeatAfter` entries.
*
* Note that `repeatAfter` defaults to `numEntries` and `numEntries`
* defaults to 5.
*/
export declare const expBackoff: (startMs: number, { repeatAfter, numEntries }?: {
repeatAfter?: number | undefined;
numEntries?: number | undefined;
}) => number[];
export declare const expBackoff: (startMs: number, options?: BackoffOptions | undefined) => number[];
export declare function defer<A>(): Deferred<A>;

@@ -16,0 +16,0 @@ /**

@@ -16,4 +16,9 @@ "use strict";

* `repeatAfter` entries.
*
* Note that `repeatAfter` defaults to `numEntries` and `numEntries`
* defaults to 5.
*/
const expBackoff = (startMs, { repeatAfter = 5, numEntries = 5 } = {}) => {
const expBackoff = (startMs, options) => {
const numEntries = options?.numEntries || 5;
const repeatAfter = options?.repeatAfter || numEntries;
const vals = [];

@@ -20,0 +25,0 @@ let val = startMs;

@@ -41,2 +41,6 @@ "use strict";

});
(0, globals_1.test)('should return desired number of entries without repeating', () => {
const result = (0, util_1.expBackoff)(1000, { numEntries: 7 });
(0, globals_1.expect)(result).toEqual([1000, 2000, 4000, 8000, 16000, 32000, 64000]);
});
(0, globals_1.test)('should limit entries according to numEntries', () => {

@@ -50,2 +54,6 @@ const result = (0, util_1.expBackoff)(1000, { numEntries: 3 });

});
(0, globals_1.test)('should respect all options', () => {
const result = (0, util_1.expBackoff)(5000, { repeatAfter: 4, numEntries: 6 });
(0, globals_1.expect)(result).toEqual([5000, 10000, 20000, 40000, 40000, 40000]);
});
});
{
"name": "nats-jobs",
"version": "0.3.0",
"version": "0.4.0",
"description": "Background job processor using NATS",

@@ -5,0 +5,0 @@ "author": "GovSpend",

@@ -97,4 +97,4 @@ import ms from 'ms'

/**
* Start processing jobs based on def. To gracefully shutdown
* see stop method.
* Call `start` to begin processing jobs based on def. To
* gracefully shutdown call `stop` method.
*/

@@ -129,3 +129,3 @@ export const jobProcessor = async (opts?: ConnectionOptions) => {

const ps = await createConsumer(conn, def)
// Get consumer info
// Get ack wait time
const ackWait = consumerDefaults(def).ack_wait

@@ -132,0 +132,0 @@ // Pull messages from the consumer

@@ -33,1 +33,6 @@ import {

export type StopFn = () => Promise<void>
export interface BackoffOptions {
numEntries?: number
repeatAfter?: number
}

@@ -42,2 +42,6 @@ import { describe, expect, test } from '@jest/globals'

})
test('should return desired number of entries without repeating', () => {
const result = expBackoff(1000, { numEntries: 7 })
expect(result).toEqual([1000, 2000, 4000, 8000, 16000, 32000, 64000])
})
test('should limit entries according to numEntries', () => {

@@ -51,2 +55,6 @@ const result = expBackoff(1000, { numEntries: 3 })

})
test('should respect all options', () => {
const result = expBackoff(5000, { repeatAfter: 4, numEntries: 6 })
expect(result).toEqual([5000, 10000, 20000, 40000, 40000, 40000])
})
})
import ms from 'ms'
import { Deferred } from './types'
import { BackoffOptions, Deferred } from './types'
import { JsMsg, Nanos } from 'nats'

@@ -12,7 +12,9 @@

* `repeatAfter` entries.
*
* Note that `repeatAfter` defaults to `numEntries` and `numEntries`
* defaults to 5.
*/
export const expBackoff = (
startMs: number,
{ repeatAfter = 5, numEntries = 5 } = {}
) => {
export const expBackoff = (startMs: number, options?: BackoffOptions) => {
const numEntries = options?.numEntries || 5
const repeatAfter = options?.repeatAfter || numEntries
const vals = []

@@ -19,0 +21,0 @@ let val = startMs

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