Skip to content

Commit

Permalink
fix: make optional mongo-collection optional and allow dates for dates (
Browse files Browse the repository at this point in the history
agenda#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
  • Loading branch information
Jonas Strassel authored Mar 1, 2021
1 parent c612f84 commit 29267cb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/agenda/db-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const debug = createDebugger("agenda:db_init");
*/
export const dbInit = function (
this: Agenda,
collection: string | undefined,
collection = "agendaJobs",
cb?: (error: Error, collection: Collection<any> | null) => void
): void {
debug("init database collection using name [%s]", collection);
this._collection = this._mdb.collection(collection || "agendaJobs"); // eslint-disable-line @typescript-eslint/prefer-nullish-coalescing
this._collection = this._mdb.collection(collection);
debug("attempting index creation");
this._collection.createIndex(
this._indices,
Expand Down
12 changes: 6 additions & 6 deletions lib/agenda/every.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const every = async function (
this: Agenda,
interval: string,
names: string | string[],
data: unknown,
options: JobOptions
data?: unknown,
options?: JobOptions
): Promise<any> {
/**
* Internal method to setup job that gets run every interval
Expand All @@ -33,8 +33,8 @@ export const every = async function (
const createJob = async (
interval: string,
name: string,
data: unknown,
options: JobOptions
data?: unknown,
options?: JobOptions
): Promise<Job> => {
const job = this.create(name, data);

Expand All @@ -54,8 +54,8 @@ export const every = async function (
const createJobs = async (
interval: string,
names: string[],
data: unknown,
options: JobOptions
data?: unknown,
options?: JobOptions
): Promise<Job[] | undefined> => {
try {
const jobs: Array<Promise<Job>> = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/agenda/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Agenda } from ".";
export const mongo = function (
this: Agenda,
mdb: Db,
collection: string | undefined,
collection?: string,
cb?: (error: Error, collection: Collection<any> | null) => void
): Agenda {
this._mdb = mdb;
Expand Down
6 changes: 3 additions & 3 deletions lib/agenda/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const debug = createDebugger("agenda:schedule");
*/
export const schedule = function (
this: Agenda,
when: string,
when: string | Date,
names: string[],
data: any
): undefined | Promise<Job | Job[]> {
Expand All @@ -27,7 +27,7 @@ export const schedule = function (
* @returns instance of new job
*/
const createJob = async (
when: string,
when: string | Date,
name: string,
data: any
): Promise<Job> => {
Expand All @@ -46,7 +46,7 @@ export const schedule = function (
* @returns jobs that were created
*/
const createJobs = async (
when: string,
when: string | Date,
names: string[],
data: any
): Promise<Job[]> => {
Expand Down
6 changes: 5 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export { Agenda, AgendaConfig } from "./agenda";
export * from "./agenda";
export * from "./job";

export { DefineOptions, JobPriority, Processor } from "./agenda/define";
export { JobOptions } from "./job/repeat-every";

import { Agenda } from "./agenda";
export default Agenda;

0 comments on commit 29267cb

Please sign in to comment.