Skip to content

Support retrieving future jobs in advance, for moving to a short-term queue (e.g. SQS) #315

@gregplaysguitar

Description

@gregplaysguitar

Feature description

When configuring worker to retrieve and process jobs, support a per-task-type time offset which controls how far in the future to look for jobs. For example, if the configured offset was 10 minutes, worker would process jobs up to 10 minutes prior to their run_at value. By default, this offset would be null and the behaviour would remain unchanged.

The point of this offset is to allow future jobs to be moved to a more scalable short-term queue. For example, SQS scales out arbitrarily and supports message delays of up to 15 minutes. So a worker task configured to retrieve jobs up to 15 minutes in future could just move them to SQS with an appropriate delay, and SQS would do the actual job processing.

In combination with the functionality proposed in #99, this change would make worker capable of dealing with orders of magnitude more scale as a job scheduler.

Motivating example

Right now, worker does a great job of scheduling future jobs and processing them efficiently, however there are limits to how far it can scale on a single-node database. This is particularly noticeable when a large number of jobs are scheduled for the same time. To give a real example - 100,000 notifications scheduled for publish at 9am on Monday morning. In practice worker can't process 100k tasks all at once so task processing is spread over a period of time - with worker concurrency at say, 100 and jobs taking 200ms to process, some notifications end up 3-4 minutes late.

With a run_at offset configured to 10 minutes, and a task set up to forward jobs to SQS, worker would have 10 minutes to retrieve and process all 100k jobs from the database rather than having them all suddenly available to process at once. SQS has a limit of 120k in-flight messages so in theory it could actually process these all at once - depending on the limits of the surrounding systems of course!

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