Skip to content

Commit

Permalink
feat(defer): rename defer.schedule() to defer.cron()
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypoly committed Feb 25, 2023
1 parent a8bc8f0 commit fe251f2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
20 changes: 20 additions & 0 deletions .changeset/unlucky-rocks-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@defer/client": major
---

BREAKING CHANGE:
- Renamed `defer.schedule()` to `defer.cron()`
- `defer.cron()` no longer takes a english string but a CRON tab string

```ts
import { defer } from '@defer.run/client'

const weeklyBrief = async () => {
// ...
}

export default defer.schedule(
weeklyBrief,
'5 0 * * *'
)
```
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"author": "Defer Inc <support@defer.run>",
"license": "ISC",
"dependencies": {
"@darkeyedevelopers/natural-cron.js": "^1.1.0",
"@whatwg-node/fetch": "^0.2.9",
"parse-duration": "^1.0.2"
},
Expand Down
12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import parseDuration, { Units } from "parse-duration";
// @ts-expect-error untyped dep
import getCronString from "@darkeyedevelopers/natural-cron.js";
import { INTERNAL_VERSION } from "./constants.js";

const FakeID = "00000000000000000000000000000000";
Expand Down Expand Up @@ -137,7 +135,7 @@ export interface Defer {
fn: F,
options?: DeferOptions
): DeferRetFn<F>;
schedule: <F extends (args: never[]) => Promise<any>>(
cron: <F extends (args: never[]) => Promise<any>>(
fn: F,
schedule: string
) => DeferScheduledFn<F>;
Expand Down Expand Up @@ -239,15 +237,15 @@ export const defer: Defer = (fn, options) => {
return ret;
};

defer.schedule = (fn, schedule) => {
defer.cron = (fn, schedule) => {
const ret: DeferScheduledFn<typeof fn> = () => {
throw new Error("`defer.scheduled()` functions should not be invoked.");
throw new Error("`defer.cron()` functions should not be invoked.");
};

ret.__fn = fn;
ret.__metadata = {
version: INTERNAL_VERSION,
cron: getCronString(schedule) as string,
cron: schedule,
};

return ret;
Expand Down Expand Up @@ -329,7 +327,7 @@ export const delay: DeferDelay =
// return 1;
// }

// defer.schedule(myFunction, "every day");
// defer.cron(myFunction, "every day");

// async function test() {
// await importContactsD("1", []); // fire and forget
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,6 @@
dependencies:
"@jridgewell/trace-mapping" "0.3.9"

"@darkeyedevelopers/natural-cron.js@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@darkeyedevelopers/natural-cron.js/-/natural-cron.js-1.1.0.tgz#d77721f6ea5912d9d114db6b0dbe6aa26eb7b235"
integrity sha512-CBRydMA7ExsLF6Ukmhf5QeUcv64RVfS417MqRZhN97hle1bDTJuT91AwO1K7gez/41uLSH6We07TqNp/XeLryA==

"@esbuild/linux-loong64@0.14.54":
version "0.14.54"
resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.14.54.tgz#de2a4be678bd4d0d1ffbb86e6de779cde5999028"
Expand Down

0 comments on commit fe251f2

Please sign in to comment.