Fix agenda constructor options

This commit is contained in:
Matthew Bull
2018-08-27 14:52:56 +01:00
parent 5e58f71c5e
commit a4717a1f48
2 changed files with 10 additions and 13 deletions

View File

@@ -1,10 +1,14 @@
import Agenda = require("agenda");
import { Db, Server } from "mongodb";
import { Db, Server, MongoClient } from "mongodb";
var mongoConnectionString = "mongodb://127.0.0.1/agenda";
(async () => {
var agenda = new Agenda({ db: { address: mongoConnectionString } });
var agenda = new Agenda({
mongo: (await MongoClient.connect(mongoConnectionString)).db(),
db: { collection: 'agenda-jobs' },
});
agenda.define<{ foo: Error }>('delete old users', (job, done) => {
done(job.attrs.data.foo)

View File

@@ -203,17 +203,7 @@ declare namespace Agenda {
/**
* Specifies that Agenda should be initialized using and existing MongoDB connection.
*/
mongo?: {
/**
* The MongoDB database connection to use.
*/
db: Db;
/**
* The name of the collection to use.
*/
collection?: string;
}
mongo?: Db;
/**
* Specifies that Agenda should connect to MongoDB.
@@ -221,8 +211,10 @@ declare namespace Agenda {
db?: {
/**
* The connection URL.
* Required when using `db` option to connect.
* Not required when an existing connection is passed as `mongo` property.
*/
address: string;
address?: string;
/**
* The name of the collection to use.
@@ -231,6 +223,7 @@ declare namespace Agenda {
/**
* Connection options to pass to MongoDB.
* Not required when an existing connection is passed as `mongo` property.
*/
options?: any;
}