Socket
Socket
Sign inDemoInstall

agenda

Package Overview
Dependencies
180
Maintainers
8
Versions
88
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.2.0 to 4.2.1

4

dist/agenda/cancel.d.ts
import { Agenda } from ".";
import { FilterQuery } from "mongodb";
import { Document, Filter } from "mongodb";
/**

@@ -10,3 +10,3 @@ * Cancels any jobs matching the passed MongoDB query, and removes them from the database.

*/
export declare const cancel: (this: Agenda, query: FilterQuery<any>) => Promise<number | undefined>;
export declare const cancel: (this: Agenda, query: Filter<Document>) => Promise<number | undefined>;
//# sourceMappingURL=cancel.d.ts.map

@@ -30,5 +30,5 @@ "use strict";

try {
const { result } = yield this._collection.deleteMany(query);
debug("%s jobs cancelled", result.n);
return result.n;
const { deletedCount } = yield this._collection.deleteMany(query);
debug("%s jobs cancelled", deletedCount);
return deletedCount;
}

@@ -35,0 +35,0 @@ catch (error) {

@@ -7,3 +7,3 @@ import { Agenda } from ".";

* @function
* @param [option]: { force: boolean } Force close, emitting no events
* @param [option] {{ force: boolean }} Force close, emitting no events
*

@@ -10,0 +10,0 @@ *

@@ -23,3 +23,3 @@ "use strict";

* @function
* @param [option]: { force: boolean } Force close, emitting no events
* @param [option] {{ force: boolean }} Force close, emitting no events
*

@@ -26,0 +26,0 @@ *

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

import { Collection, MongoClientOptions } from "mongodb";
import { AnyError, Collection, MongoClientOptions } from "mongodb";
import { Agenda } from ".";
/**
* Connect to the spec'd MongoDB server and database.
*
* NOTE:
* If `url` includes auth details then `options` must specify: { 'uri_decode_auth': true }. This does Auth on
* the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB,
* then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor
* or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in
* the constructor or use Agenda.mongo().
* @name Agenda#database

@@ -11,10 +18,4 @@ * @function

* @param [cb] callback of MongoDB connection
* NOTE:
* If `url` includes auth details then `options` must specify: { 'uri_decode_auth': true }. This does Auth on
* the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB,
* then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor
* or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in
* the constructor or use Agenda.mongo().
*/
export declare const database: (this: Agenda, url: string, collection?: string | undefined, options?: MongoClientOptions | undefined, cb?: ((error: Error, collection: Collection<any> | null) => void) | undefined) => Agenda | void;
export declare const database: (this: Agenda, url: string, collection?: string | undefined, options?: MongoClientOptions, cb?: ((error: AnyError | undefined, collection: Collection<any> | null) => void) | undefined) => Agenda | void;
//# sourceMappingURL=database.d.ts.map

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

exports.database = void 0;
const debug_1 = __importDefault(require("debug"));
const mongodb_1 = require("mongodb");
const debug_1 = __importDefault(require("debug"));
const has_mongo_protocol_1 = require("./has-mongo-protocol");

@@ -14,2 +14,9 @@ const debug = debug_1.default("agenda:database");

* Connect to the spec'd MongoDB server and database.
*
* NOTE:
* If `url` includes auth details then `options` must specify: { 'uri_decode_auth': true }. This does Auth on
* the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB,
* then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor
* or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in
* the constructor or use Agenda.mongo().
* @name Agenda#database

@@ -21,22 +28,8 @@ * @function

* @param [cb] callback of MongoDB connection
* NOTE:
* If `url` includes auth details then `options` must specify: { 'uri_decode_auth': true }. This does Auth on
* the specified database, not the Admin database. If you are using Auth on the Admin DB and not on the Agenda DB,
* then you need to authenticate against the Admin DB and then pass the MongoDB instance into the constructor
* or use Agenda.mongo(). If your app already has a MongoDB connection then use that. ie. specify config.mongo in
* the constructor or use Agenda.mongo().
*/
const database = function (url, collection, options, cb) {
const database = function (url, collection, options = {}, cb) {
if (!has_mongo_protocol_1.hasMongoProtocol(url)) {
url = "mongodb://" + url;
}
const reconnectOptions = (options === null || options === void 0 ? void 0 : options.useUnifiedTopology) === true
? {}
: {
autoReconnect: true,
reconnectTries: Number.MAX_SAFE_INTEGER,
reconnectInterval: this._processEvery,
};
collection = collection || "agendaJobs";
options = Object.assign(Object.assign({}, reconnectOptions), options);
mongodb_1.MongoClient.connect(url, options, (error, client) => {

@@ -54,5 +47,10 @@ if (error) {

debug("successful connection to MongoDB using collection: [%s]", collection);
this._db = client;
this._mdb = client.db();
this.db_init(collection, cb);
if (client) {
this._db = client;
this._mdb = client.db();
this.db_init(collection, cb);
}
else {
throw new Error("Mongo Client is undefined");
}
});

@@ -59,0 +57,0 @@ return this;

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

import { Collection } from "mongodb";
import { AnyError, Collection } from "mongodb";
import { Agenda } from ".";

@@ -10,3 +10,3 @@ /**

*/
export declare const dbInit: (this: Agenda, collection?: string, cb?: ((error: Error, collection: Collection<any> | null) => void) | undefined) => void;
export declare const dbInit: (this: Agenda, collection?: string, cb?: ((error: AnyError | undefined, collection: Collection<any> | null) => void) | undefined) => void;
//# sourceMappingURL=db-init.d.ts.map

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

import { FilterQuery } from "mongodb";
import { Filter } from "mongodb";
import { Agenda } from ".";

@@ -10,3 +10,3 @@ /**

*/
export declare const disable: (this: Agenda, query?: FilterQuery<unknown>) => Promise<number>;
export declare const disable: (this: Agenda, query?: Filter<unknown>) => Promise<number>;
//# sourceMappingURL=disable.d.ts.map

@@ -29,7 +29,7 @@ "use strict";

try {
const { result } = yield this._collection.updateMany(query, {
const { modifiedCount } = yield this._collection.updateMany(query, {
$set: { disabled: true },
});
debug("%s jobs disabled", result.n);
return result.n;
debug("%s jobs disabled");
return modifiedCount;
}

@@ -36,0 +36,0 @@ catch (error) {

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

import { FilterQuery } from "mongodb";
import { Filter } from "mongodb";
import { Agenda } from ".";

@@ -11,3 +11,3 @@ /**

*/
export declare const enable: (this: Agenda, query?: FilterQuery<unknown>) => Promise<number>;
export declare const enable: (this: Agenda, query?: Filter<unknown>) => Promise<number>;
//# sourceMappingURL=enable.d.ts.map

@@ -30,7 +30,7 @@ "use strict";

try {
const { result } = yield this._collection.updateMany(query, {
const { modifiedCount } = yield this._collection.updateMany(query, {
$set: { disabled: false },
});
debug("%s jobs enabled", result.n);
return result.n;
debug("%s jobs enabled", modifiedCount);
return modifiedCount;
}

@@ -37,0 +37,0 @@ catch (error) {

@@ -33,63 +33,42 @@ "use strict";

debug("_findAndLockNextJob(%s, [Function])", jobName);
// Don't try and access MongoDB if we've lost connection to it.
// Trying to resolve crash on Dev PC when it resumes from sleep. NOTE: Does this still happen?
// @ts-expect-error
const s = this._mdb.s || this._mdb.db.s;
if (s.topology.connections &&
s.topology.connections().length === 0 &&
!this._mongoUseUnifiedTopology) {
if (s.topology.autoReconnect && !s.topology.isDestroyed()) {
// Continue processing but notify that Agenda has lost the connection
debug("Missing MongoDB connection, not attempting to find and lock a job");
this.emit("error", new Error("Lost MongoDB connection"));
}
else {
// No longer recoverable
debug("topology.autoReconnect: %s, topology.isDestroyed(): %s", s.topology.autoReconnect, s.topology.isDestroyed());
throw new Error("MongoDB connection is not recoverable, application restart required");
}
const JOB_PROCESS_WHERE_QUERY = {
$and: [
{
name: jobName,
disabled: { $ne: true },
},
{
$or: [
{
lockedAt: { $eq: null },
nextRunAt: { $lte: this._nextScanAt },
},
{
lockedAt: { $lte: lockDeadline },
},
],
},
],
};
/**
* Query used to set a job as locked
* @type {{$set: {lockedAt: Date}}}
*/
const JOB_PROCESS_SET_QUERY = { $set: { lockedAt: now } };
/**
* Query used to affect what gets returned
* @type {{returnOriginal: boolean, sort: object}}
*/
const JOB_RETURN_QUERY = { returnDocument: "after", sort: this._sort };
// Find ONE and ONLY ONE job and set the 'lockedAt' time so that job begins to be processed
const result = yield this._collection.findOneAndUpdate(JOB_PROCESS_WHERE_QUERY, JOB_PROCESS_SET_QUERY,
// @ts-ignore
JOB_RETURN_QUERY);
let job = undefined;
if (result.value) {
debug("found a job available to lock, creating a new job on Agenda with id [%s]", result.value._id);
// @ts-ignore
job = utils_1.createJob(this, result.value);
}
else {
// /**
// * Query used to find job to run
// * @type {{$and: [*]}}
// */
const JOB_PROCESS_WHERE_QUERY = {
$and: [
{
name: jobName,
disabled: { $ne: true },
},
{
$or: [
{
lockedAt: { $eq: null },
nextRunAt: { $lte: this._nextScanAt },
},
{
lockedAt: { $lte: lockDeadline },
},
],
},
],
};
/**
* Query used to set a job as locked
* @type {{$set: {lockedAt: Date}}}
*/
const JOB_PROCESS_SET_QUERY = { $set: { lockedAt: now } };
/**
* Query used to affect what gets returned
* @type {{returnOriginal: boolean, sort: object}}
*/
const JOB_RETURN_QUERY = { returnOriginal: false, sort: this._sort };
// Find ONE and ONLY ONE job and set the 'lockedAt' time so that job begins to be processed
const result = yield this._collection.findOneAndUpdate(JOB_PROCESS_WHERE_QUERY, JOB_PROCESS_SET_QUERY, JOB_RETURN_QUERY);
let job = undefined;
if (result.value) {
debug("found a job available to lock, creating a new job on Agenda with id [%s]", result.value._id);
job = utils_1.createJob(this, result.value);
}
return job;
}
return job;
});

@@ -96,0 +75,0 @@ };

/// <reference types="node" />
import { EventEmitter } from "events";
import { MongoClient, Db as MongoDb, Collection, MongoClientOptions } from "mongodb";
import { JobProcessingQueue } from "./job-processing-queue";
import { AnyError, Collection, Db as MongoDb, MongoClient, MongoClientOptions } from "mongodb";
import { Job } from "../job";
import { cancel } from "./cancel";

@@ -17,2 +17,3 @@ import { close } from "./close";

import { every } from "./every";
import { JobProcessingQueue } from "./job-processing-queue";
import { jobs } from "./jobs";

@@ -31,3 +32,2 @@ import { lockLimit } from "./lock-limit";

import { stop } from "./stop";
import { Job } from "../job";
export interface AgendaConfig {

@@ -75,3 +75,3 @@ name?: string;

_definitions: any;
_findAndLockNextJob: any;
_findAndLockNextJob: (this: Agenda, jobName: string, definition: any) => Promise<Job<import("../job").JobAttributesData> | undefined>;
_indices: any;

@@ -126,5 +126,5 @@ _isLockingOnTheFly: boolean;

*/
constructor(config?: AgendaConfig, cb?: (error: Error, collection: Collection<any> | null) => void);
constructor(config?: AgendaConfig, cb?: (error: AnyError | undefined, collection: Collection<any> | null) => void);
}
export { Agenda };
//# sourceMappingURL=index.d.ts.map

@@ -7,5 +7,4 @@ "use strict";

exports.Agenda = void 0;
const events_1 = require("events");
const human_interval_1 = __importDefault(require("human-interval"));
const events_1 = require("events");
const job_processing_queue_1 = require("./job-processing-queue");
const cancel_1 = require("./cancel");

@@ -23,2 +22,4 @@ const close_1 = require("./close");

const every_1 = require("./every");
const find_and_lock_next_job_1 = require("./find-and-lock-next-job");
const job_processing_queue_1 = require("./job-processing-queue");
const jobs_1 = require("./jobs");

@@ -37,3 +38,2 @@ const lock_limit_1 = require("./lock-limit");

const stop_1 = require("./stop");
const find_and_lock_next_job_1 = require("./find-and-lock-next-job");
/**

@@ -69,2 +69,3 @@ * @class Agenda

super();
this._findAndLockNextJob = find_and_lock_next_job_1.findAndLockNextJob;
this._name = config.name;

@@ -103,3 +104,2 @@ this._processEvery = ((_a = human_interval_1.default(config.processEvery)) !== null && _a !== void 0 ? _a : human_interval_1.default("5 seconds")); // eslint-disable-line @typescript-eslint/non-nullable-type-assertion-style

exports.Agenda = Agenda;
Agenda.prototype._findAndLockNextJob = find_and_lock_next_job_1.findAndLockNextJob;
Agenda.prototype.cancel = cancel_1.cancel;

@@ -106,0 +106,0 @@ Agenda.prototype.close = close_1.close;

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

import { FilterQuery } from "mongodb";
import { Filter } from "mongodb";
import { Agenda } from ".";

@@ -14,3 +14,3 @@ import { Job } from "../job";

*/
export declare const jobs: (this: Agenda, query?: FilterQuery<any>, sort?: {}, limit?: number, skip?: number) => Promise<Job[]>;
export declare const jobs: (this: Agenda, query?: Filter<any>, sort?: {}, limit?: number, skip?: number) => Promise<Job[]>;
//# sourceMappingURL=jobs.d.ts.map

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

import { Collection, Db } from "mongodb";
import { AnyError, Collection, Db } from "mongodb";
import { Agenda } from ".";

@@ -11,3 +11,3 @@ /**

*/
export declare const mongo: (this: Agenda, mdb: Db, collection?: string | undefined, cb?: ((error: Error, collection: Collection<any> | null) => void) | undefined) => Agenda;
export declare const mongo: (this: Agenda, mdb: Db, collection?: string | undefined, cb?: ((error: AnyError | undefined, collection: Collection<any> | null) => void) | undefined) => Agenda;
//# sourceMappingURL=mongo.d.ts.map

@@ -31,11 +31,25 @@ "use strict";

// findOneAndUpdate() returns different results than insertOne() so check for that
let resultValue = result.ops ? result.ops : result.value;
let resultValue = result.insertedId ? result.insertedId : result.value;
if (resultValue) {
// If it is an array, grab the first job
if (Array.isArray(resultValue)) {
resultValue = resultValue[0];
let _id;
let nextRunAt;
if (result.insertedId) {
_id = result.insertedId;
// find the doc using _id
const _job = yield this._collection.findOne({ _id });
if (_job) {
nextRunAt = _job.nextRunAt;
}
}
else {
// If it is an array, grab the first job
if (Array.isArray(resultValue)) {
resultValue = resultValue[0];
}
_id = resultValue._id;
nextRunAt = resultValue.nextRunAt;
}
// Grab ID and nextRunAt from MongoDB and store it as an attribute on Job
job.attrs._id = resultValue._id;
job.attrs.nextRunAt = resultValue.nextRunAt;
job.attrs._id = _id;
job.attrs.nextRunAt = nextRunAt;
// If the current job would have been processed in an older scan, process the job immediately

@@ -83,3 +97,3 @@ if (job.attrs.nextRunAt && job.attrs.nextRunAt < this._nextScanAt) {

debug("job already has _id, calling findOneAndUpdate() using _id as query");
const result = yield this._collection.findOneAndUpdate({ _id: id }, update, { returnOriginal: false });
const result = yield this._collection.findOneAndUpdate({ _id: id }, update, { returnDocument: "after" });
return yield processDbResult.call(this, job, result);

@@ -112,3 +126,3 @@ }

upsert: true,
returnOriginal: false,
returnDocument: "after",
});

@@ -129,3 +143,3 @@ return yield processDbResult.call(this, job, result);

upsert: true,
returnOriginal: false,
returnDocument: "after",
});

@@ -132,0 +146,0 @@ return yield processDbResult.call(this, job, result);

@@ -25,3 +25,3 @@ import { toJson } from "./to-json";

*/
_id?: mongodb.ObjectID;
_id?: mongodb.ObjectId;
agenda: Agenda;

@@ -28,0 +28,0 @@ /**

@@ -139,6 +139,8 @@ "use strict";

const update = { $set: { lockedAt: now } };
const options = { returnOriginal: false };
// Lock the job in MongoDB!
const resp = yield self._collection.findOneAndUpdate(criteria, update, options);
const resp = yield self._collection.findOneAndUpdate(criteria, update, {
returnDocument: "after",
});
if (resp.value) {
// @ts-ignore
const job = create_job_1.createJob(self, resp.value);

@@ -145,0 +147,0 @@ debug("found job [%s:%s] that can be locked on the fly", job.attrs.name, job.attrs._id);

@@ -7,6 +7,6 @@ # Next

- Feat: Add top level disable and enable (#1109) thanks @pdfowler
- fix(history): match cron-parser pattern (#1335) thanks @dockleryxk
- fix: "RangeError: Maximum call stack size exceeded" (#1365) thanks @koresar
- fix: JobAttributes.lockedAt to allow null values (#1340) thanks @tjramage
- Feat: Add top level disable and enable ([#1109](https://github.com/agenda/agenda/pull/1109)) thanks @pdfowler
- fix(history): match cron-parser pattern ([#1335](https://github.com/agenda/agenda/pull/1335)) thanks @dockleryxk
- fix: "RangeError: Maximum call stack size exceeded" ([#1365](https://github.com/agenda/agenda/pull/1365)) thanks @koresar
- fix: JobAttributes.lockedAt to allow null values ([#1340](https://github.com/agenda/agenda/pull/1340)) thanks @tjramage
- Updated dependencies: `mongodb@3.6.6`, `lodash@4.17.21`, as well as various dev dependencies.

@@ -13,0 +13,0 @@ - Added node 16 in tests ([#1314](https://github.com/agenda/agenda/pull/1086)) thanks @simison

{
"name": "agenda",
"version": "4.2.0",
"version": "4.2.1",
"description": "Light weight job scheduler for Node.js",

@@ -12,3 +12,3 @@ "main": "dist/cjs.js",

"engines": {
"node": ">=10.0.0"
"node": ">=12.9.0"
},

@@ -21,6 +21,10 @@ "scripts": {

"lint": "eslint --cache --fix lib/**",
"mocha": "mocha --reporter spec --timeout 8000 -b",
"mocha-debug": "DEBUG=agenda:**,-agenda:internal:** mocha --reporter spec --timeout 8000 -b",
"mocha-debug-internal": "DEBUG=agenda:internal:** mocha --reporter spec --timeout 8000 -b",
"mocha-debug-all": "DEBUG=agenda:** mocha --reporter spec --timeout 8000 -b",
"mocha": "USE_MONGODB=true mocha --reporter spec --timeout 8000 --exit -b",
"premocha-debug": "npm run build",
"mocha-debug": "USE_MONGODB=true DEBUG=agenda:**,-agenda:internal:** mocha --reporter spec --timeout 8000 -b",
"premocha-debug-internal": "npm run build",
"mocha-debug-internal": "USE_MONGODB=true DEBUG=agenda:internal:** mocha --reporter spec --timeout 8000 -b",
"premocha-debug-all": "npm run build",
"mocha-debug-all": "USE_MONGODB=true DEBUG=agenda:** mocha --reporter spec --timeout 8000 -b",
"postversion": "npm run docs",
"predocs": "npm run build",

@@ -58,3 +62,3 @@ "docs": "jsdoc --configure .jsdoc.json --verbose ./dist"

"moment-timezone": "~0.5.27",
"mongodb": "~3.6.6"
"mongodb": "^4.1.0"
},

@@ -64,9 +68,8 @@ "devDependencies": {

"@types/human-interval": "1.0.0",
"@types/mongodb": "3.6.14",
"@typescript-eslint/eslint-plugin": "4.25.0",
"@typescript-eslint/parser": "4.25.0",
"@typescript-eslint/eslint-plugin": "4.29.0",
"@typescript-eslint/parser": "4.29.0",
"blanket": "1.2.3",
"coveralls": "3.1.0",
"coveralls": "3.1.1",
"delay": "5.0.0",
"eslint": "7.27.0",
"eslint": "7.32.0",
"eslint-config-prettier": "8.3.0",

@@ -81,5 +84,6 @@ "esm": "3.2.25",

"mocha-lcov-reporter": "1.3.0",
"prettier": "2.3.0",
"sinon": "11.1.0",
"typescript": "4.2.4"
"mongodb-memory-server": "7.3.4",
"prettier": "2.3.2",
"sinon": "11.1.2",
"typescript": "4.3.5"
},

@@ -86,0 +90,0 @@ "eslintConfig": {

@@ -57,2 +57,6 @@ <p align="center">

### Notice
In order to support new MongoDB 5.0 and mongodb node.js driver/package the next release (5.x.x) of Agenda will be major. The required node version will become >=12. The mongodb dependency version will become >=3.2.
Install via NPM

@@ -67,4 +71,5 @@

for regular javascript code, just use the default entrypoint
```js
const Agenda = require('agenda');
const Agenda = require("agenda");
```

@@ -74,6 +79,8 @@

e.g.
```ts
import { Agenda } from 'agenda/es';
import { Agenda } from "agenda/es";
```
***NOTE***: If you're migrating from `@types/agenda` you also should change imports to `agenda/es`.
**_NOTE_**: If you're migrating from `@types/agenda` you also should change imports to `agenda/es`.
Instead of `import Agenda from 'agenda'` use `import Agenda from 'agenda/es'`.

@@ -557,3 +564,3 @@

```js
const numDisabled = await agenda.disable({name: 'pollExternalService'});
const numDisabled = await agenda.disable({ name: "pollExternalService" });
```

@@ -568,3 +575,3 @@

```js
const numEnabled = await agenda.enable({name: 'pollExternalService'});
const numEnabled = await agenda.enable({ name: "pollExternalService" });
```

@@ -571,0 +578,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc