Skip to content

Commit 29267cb

Browse files
author
Jonas Strassel
authored
fix: make optional mongo-collection optional and allow dates for dates (#1258)
* fix: make optional mongo-collection optional * fix: export more things from top-level * fix: allow every without data and options * fix: allow schedules on dates
1 parent c612f84 commit 29267cb

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

lib/agenda/db-init.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const debug = createDebugger("agenda:db_init");
1313
*/
1414
export const dbInit = function (
1515
this: Agenda,
16-
collection: string | undefined,
16+
collection = "agendaJobs",
1717
cb?: (error: Error, collection: Collection<any> | null) => void
1818
): void {
1919
debug("init database collection using name [%s]", collection);
20-
this._collection = this._mdb.collection(collection || "agendaJobs"); // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
20+
this._collection = this._mdb.collection(collection);
2121
debug("attempting index creation");
2222
this._collection.createIndex(
2323
this._indices,

lib/agenda/every.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const every = async function (
1919
this: Agenda,
2020
interval: string,
2121
names: string | string[],
22-
data: unknown,
23-
options: JobOptions
22+
data?: unknown,
23+
options?: JobOptions
2424
): Promise<any> {
2525
/**
2626
* Internal method to setup job that gets run every interval
@@ -33,8 +33,8 @@ export const every = async function (
3333
const createJob = async (
3434
interval: string,
3535
name: string,
36-
data: unknown,
37-
options: JobOptions
36+
data?: unknown,
37+
options?: JobOptions
3838
): Promise<Job> => {
3939
const job = this.create(name, data);
4040

@@ -54,8 +54,8 @@ export const every = async function (
5454
const createJobs = async (
5555
interval: string,
5656
names: string[],
57-
data: unknown,
58-
options: JobOptions
57+
data?: unknown,
58+
options?: JobOptions
5959
): Promise<Job[] | undefined> => {
6060
try {
6161
const jobs: Array<Promise<Job>> = [];

lib/agenda/mongo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Agenda } from ".";
1212
export const mongo = function (
1313
this: Agenda,
1414
mdb: Db,
15-
collection: string | undefined,
15+
collection?: string,
1616
cb?: (error: Error, collection: Collection<any> | null) => void
1717
): Agenda {
1818
this._mdb = mdb;

lib/agenda/schedule.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const debug = createDebugger("agenda:schedule");
1515
*/
1616
export const schedule = function (
1717
this: Agenda,
18-
when: string,
18+
when: string | Date,
1919
names: string[],
2020
data: any
2121
): undefined | Promise<Job | Job[]> {
@@ -27,7 +27,7 @@ export const schedule = function (
2727
* @returns instance of new job
2828
*/
2929
const createJob = async (
30-
when: string,
30+
when: string | Date,
3131
name: string,
3232
data: any
3333
): Promise<Job> => {
@@ -46,7 +46,7 @@ export const schedule = function (
4646
* @returns jobs that were created
4747
*/
4848
const createJobs = async (
49-
when: string,
49+
when: string | Date,
5050
names: string[],
5151
data: any
5252
): Promise<Job[]> => {

lib/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export { Agenda, AgendaConfig } from "./agenda";
1+
export * from "./agenda";
2+
export * from "./job";
23

34
export { DefineOptions, JobPriority, Processor } from "./agenda/define";
45
export { JobOptions } from "./job/repeat-every";
6+
7+
import { Agenda } from "./agenda";
8+
export default Agenda;

0 commit comments

Comments
 (0)