get-convex / get-convex/crons

cronspec is scary and I'm not sure I'm doing it right

Open
#4 2 comments 0 reactions 1 assignee Claimed by @jamescowling View on GitHub
Dominant language
TypeScript
Stars
6
Forks
6
Avg merge
10h 28m
Merged PRs (30d)
2

Description

I'm nervous about writing code that programmatically generates a cronspec string.
With the crons component I'm empowered to define these crons dynamically, but when I wanted to define one, I kept nervously checking websites for the right string format. It's also unclear if things like `1-5` work for M-F, `~` or `/` are implemented.

I'd love something typesafe that is also readable / self-describing. or suggest using some existing library to format the string, but after what I heard about the rust crons library I'd want to know which one makes the correct string format for this component.

For illustrative purposes:
```ts
{
minute: 0,
hour: getUTCHourFromTimezone(args.timezone),
dayOfMonth: ALL,
month: range(1, 5), // helper to make `[1, 2, 3, 4, 5]` that can get compressed to `1-5` for the string if we want
weekday: [weekday.Monday, weekday.Wednesday, weekday.Friday],
}
```
maybe with type pseudocode:
```ts
const ALL = "*";
type ALL = "*";
type Selection = number | number [] | ALL;
{
second?: Selection = 0
minute: Selection = ALL,
hour: Selection = ALL,
dayOfMonth?: Selection = ALL,
month?: Selection = ALL,
weekday?: Selection = ALL
}
```
allowing shorthand like:
```ts
const everySecond = { second: ALL };
const everyMinute = { minute: ALL }; // or just {}
const hourly = { minute: 0 };
const daily = { minute: 0, hour: 0 };
const weekly = { minute: 0, hour: 0, weekday: WEEKDAY.Monday };
const biweekly = { minute: 0, hour: 0, dayOfMonth: [1, 15] };
const monthly = { minute: 0, hour: 0, dayOfMonth: 1 };
const quarterly = { minute: 0, hour: 0, dayOfMonth: 1, month: [1, 7] };
const yearly = { minute: 0, hour: 0, dayOfMonth: 1, month: 1 };
const firstMondayOfNovember = { minute: 0, hour: 0, dayOfMonth: range(1, 7), month: 11, weekday: WEEKDAY.Monday };
...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.