graphile / graphile/worker

Task definition helper function (ability to define per-task defaults + typescript as a first-class citizen)

Open
#491 10 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
TypeScript
Stars
2.4k
Forks
126
Avg merge
2d 2h
Merged PRs (30d)
9

Description

### Feature description
It would be great if there was a better helper function to define tasks, such as a `createTask`, that would enable inline payload validation as well as defining task defaults (retries, and other options).

There's many cases when a task e.g. calls an expensive API, and I only want it to be retried a few times if any, and I need to always configure it at the task caller level, which makes maintenance less straight forward than it needs to be.

This change would also help make typescript a first-class citizen and tremendously improve the DX of creating typescript-based tasks, which currently involves importing helper types and "manually" parsing payloads to validate them, and manually adding types for the payload to make sure that callers are aware of them. I think Zod could easily be a first-party integration here for the helper function to define payloads, which would then help to pass them through for implementations as well.

I really like the first benchmark below.

### Motivating example
Benchmarks:
* https://x.com/ImSh4yy/status/1816677686116229522
* https://github.com/ben-pr-p/graphile-worker-zod
* https://www.inngest.com/docs/reference/functions/create
* https://trigger.dev/docs/tasks/overview

### Breaking changes
It doesn't have to come with any breaking changes.

### Supporting development

I [tick all that apply]:

- [x] am interested in building this feature myself (happy to design the helper function, but could use help from the maintainer on extending the DB schema to hold the task defaults)
- [x] am interested in collaborating on building this feature
- [x] am willing to help testing this feature before it's released
- [] am willing to write a test-driven test suite for this feature (before it exists)
- [ ] am a [Graphile sponsor](https://www.graphile.org/sponsor/) ❤️
- [ ] have an active [support or consultancy contract](https://www.graphile.org/support/) with Graphile

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.