Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds background job scheduling and execution #11238

Merged
merged 272 commits into from
Aug 21, 2024
Merged

Conversation

cannikin
Copy link
Member

@cannikin cannikin commented Aug 13, 2024

This new package provides scheduling and processing of background jobs. We want everything needed to run a modern web application to be included in Redwood itself—you shouldn't need any third party integrations if you don't want.

Background jobs have been sorely missed, but the time has come! (If you do want to use a third party service we have had an integration with Inngest since May of 2023!)

Features

  • Named queues: you can schedule jobs in separate named queues and have a different number of workers monitoring each one—makes it much easier to scale your background processing.
  • Priority: give your jobs a priority from 1 (highest) to 100 (lowest). Workers will sort available jobs by priority, working on the most important ones first.
  • Configurable delay: run your job as soon as possible (default), wait a number of seconds before running, or run at a specific time in the future.
  • Auto-retries with backoff: if your job fails it will back off at the rate of attempts ** 4 for a default of 24 tries, the time between the last two attempts is a little over three days.
  • Run inline: instead of scheduling to run in the background, run immediately.
  • Integrates with Redwood's logger: use your existing one in api/src/lib/logger or create a new one just for job logging.

Usage

Check out the docs!

The Future

  • More adapters (maybe the community wants to get involved?): Redis, SQS, RabbitMQ
  • Studio integration: monitor the state of your outstanding jobs
  • Baremetal integration: if jobs are enabled, monitor the workers
  • Recurring jobs
  • Lifecycle hooks: beforePerform(), afterPerform(), afterSuccess(), afterFailure()

TODO

  • Update docs

Thanks to @Josh-Walker-GM for the help in the recent refactor!

Closes #11122

@Josh-Walker-GM Josh-Walker-GM merged commit 865ff5c into main Aug 21, 2024
45 checks passed
@Josh-Walker-GM Josh-Walker-GM deleted the rc-background-jobs branch August 21, 2024 03:06
packages/jobs/src/core/JobManager.ts Show resolved Hide resolved
packages/jobs/src/core/Worker.ts Show resolved Hide resolved

You'll most likely be scheduling work as the result of one of your service functions being executed. Let's say we want to schedule our `SampleJob` whenever a new user is created:

```js title="api/src/services/users/users.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add TS versions of all code listings as well (as we do for our tutorial, so the user gets an option to switch between TS and JS)

docs/docs/background-jobs.md Show resolved Hide resolved
dac09 added a commit to dac09/redwood that referenced this pull request Aug 22, 2024
…into feat/rw-uploads-extension

* 'feat/rw-uploads-extension' of github.com:dac09/redwood:
  chore(test-fixture): correct rebuild script string suffix substitution  (redwoodjs#11339)
  refactor(forms): Build with esbuild and add conditional exports (redwoodjs#11338)
  refactor(prerender): build with esbuild and introduce conditional exports (redwoodjs#11337)
  Adds more tests! Refactor rw-jobs-worker  (redwoodjs#11335)
  refactor(auth-providers): switch to esbuild for some 'web' packages (redwoodjs#11334)
  Jobs doc updates (redwoodjs#11333)
  chore(ci): Split formatting check into separate job  (redwoodjs#11332)
  Updates caching doc code snippets to be consistent (redwoodjs#11331)
  chore(tsconfig): Properly link to api-server's tsconfig (redwoodjs#11330)
  Adds background job scheduling and execution (redwoodjs#11238)
  [gh11317] Added documentation for working with Jest and Alias Paths (redwoodjs#11323)
  fix(record): Update dependencies and build dual esm/cjs (redwoodjs#11300)
  chore(build): Consistent tsconfig and buildinfo naming for CJS (redwoodjs#11326)
  chore(test): Fix RSC server cell smoke test (redwoodjs#11327)
  chore(playwright): Make RSC tests less flakey (redwoodjs#11325)
  chore(ci): Temporary fix for format checking on all PRs (redwoodjs#11324)
  chore(build): Move more repetitive code into framework-tools (redwoodjs#11320)
  chore(docs): fix docs formatting (redwoodjs#11321)
@Josh-Walker-GM Josh-Walker-GM modified the milestones: next-release, v8.0.0 Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixture-ok Override the test project fixture check release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Background Jobs: Re-work to procedural design
4 participants