graphile / graphile/worker

Give a way to access the `escapedWorkerSchema` or get a job by its key

Open
#548 8 comments 0 reactions 0 assignees View on GitHub
docs
Dominant language
TypeScript
Stars
2.4k
Forks
126
Avg merge
2d 2h
Merged PRs (30d)
9

Description

### Feature description

Facilitate retrieval of jobs in graphile, by either giving ways to query the schema or exposing new helpers to do so in a more durable way.

### Motivating example

Loosely inspired by https://github.com/politics-rewired/graphile-worker-rate-limiter, I have written a reusable configuration factory that allows a task `C` to be executed only once a task `A` and `B` have been executed. It behaves like so:

```ts
const compositeTask = new CompositeTask({
name: 'C',
dependencies: {
A : (payload) => payload.id,
B : (payload) => payload.id
}
});
// install composite task somehow, omitting for brievety
workerUtils.addJob('A', {foo: 'bar', id: 1}) // Nothing happens
workerUtils.addJob('B', {baz: 'qux', id: 2}) // Nothing happens
workerUtils.addJob('B', {hello: 'world', id: 1}) // Task C is ran with `{A: {foo: 'bar', id: 1}, B: {hello: 'world', id: 1}}`
```

My implementation works flawlessly. However, to work, each dependency task (`A` & `B`) need to alter the payload and retrieve the flags, and I can't find a way to do it than the brittle way of querying directly the DB but this requires knowing the graphile schema during initial configuration. I could get away without mutating the payload but the flags is the core behavior to allow a task C to be ran.

I am aware that _reading_ from the jobs table is discouraged but the total impossibility to do so even in the cases where it is needed pushes users towards hacking around.

### Breaking changes

### Supporting development

I [tick all that apply]:

- [x] am interested in building this feature myself
- [x] am interested in collaborating on building this feature
- [x] am willing to help testing this feature before it's released
- [x] 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.