Skip to content

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

@GerkinDev

Description

@GerkinDev

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:

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]:

  • am interested in building this feature myself
  • am interested in collaborating on building this feature
  • 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 ❤️
  • have an active support or consultancy contract with Graphile

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions