Skip to content

Commit

Permalink
update cron docs (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky authored Mar 26, 2024
1 parent d7fb6dd commit fffbb93
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions deploy/kv/manual/cron.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ Deno.cron("Log a message", "* * * * *", () => {
});
```

It's also possible to use JavaScript objects to define the cron schedule. In the
example below, we configure a block of JavaScript code that will execute once an
hour.

```ts
Deno.cron("Log a message", { hour: { every: 1 } }, () => {
console.log("This will print once an hour.");
});
```

`Deno.cron` takes three arguments:

- A human-readable name for the cron task
- A [cron schedule string](https://cronitor.io/guides/cron-jobs) that defines a
schedule on which the cron job will run
- A cron schedule string or JavaScript object that defines a schedule on which
the cron job will run
- a function to be executed on the given schedule

If you are new to cron syntax, it might be useful to check out
[crontab.guru](https://crontab.guru/), a browser-based tool that provides an
interactive interface to experiment with different cron syntaxes. There are also
a number of third party modules
If you are new to cron syntax, there are a number of third party modules
[like this one](https://www.npmjs.com/package/cron-time-generator) that will
help you generate cron schedule strings.

Expand Down Expand Up @@ -74,6 +81,12 @@ It's possible for the next scheduled invocation of your cron task to overlap
with the previous invocation. If this occurs, `Deno.cron` will skip the next
scheduled invocation in order to avoid overlapping executions.

### Day-of-week numeric representation

`Deno.cron` does not use 0-based day-of-week numeric representation. Instead, it
uses 1-7 (or SUN-SAT) to represent Sunday through Saturday. This may be
different compared to other cron engines which use 0-6 representation.

## Usage on Deno Deploy

With [Deno Deploy](https://www.deno.com/deploy), you can run your background
Expand Down

0 comments on commit fffbb93

Please sign in to comment.