In this episode, we're taking a closer look at how to store extra metadata about our background jobs (or tasks) in the database, which is super useful for building a dynamic frontend that can display things like job titles and descriptions without hardcoding them anywhere in the UI.
We'll start by adding a migration to our server_tasks
table so it can store both a title
and a description
for each task. Then, we create a TypeScript interface to enforce that every server job must provide a title and description — this way, any job can have custom data attached to it, and it's always available when we need it.
Once that's set up, we'll show how to actually store this metadata when creating tasks, plugging the title and description right into our database whenever a job is created. We run through updating our job constructors so they receive the necessary data (like the server model) and show how you could start generating dynamic titles and descriptions (e.g. including the server ID in the job title).
By the end, you'll see how this makes the UI much more flexible and maintainable. Listing jobs in the frontend is now as simple as dumping out their metadata from the backend. Plus, we touch on how you could enhance this further, like recording failure reasons if a job errors out.
Basically, we're setting things up so every job is self-describing, and our UI can react to whatever's happening — no manual tweaks needed!