React Status Hooks

You can now create statuses in your Job code that lets you do some pretty cool stuff in your UI, like:

  • Show exactly what you want in your UI (with as many statuses as you want).
  • Pass arbitrary data to your UI, which you can use to render elements.
  • Update existing elements in your UI as the progress of the run continues.

Here's some example code showing for a Job that generates memes. We've created a single status generatingMemes (you can create as many as you like) and then we've updated it (you can update it as often as you like). It gives you fine-grained control over how you report progress and output data from your Job.


_29
client.defineJob({
_29
id: "meme-generator",
_29
name: "Generate memes",
_29
version: "0.1.1",
_29
trigger: eventTrigger({
_29
name: "generate-memes",
_29
}),
_29
run: async (payload, io, ctx) => {
_29
const generatingMemes = await io.createStatus("generating-memes", {
_29
label: "Generating memes",
_29
state: "loading",
_29
data: {
_29
progress: 0.1,
_29
},
_29
});
_29
_29
//...do stuff, like generate memes
_29
_29
await generatingMemes.update("middle-generation", {
_29
state: "success",
_29
data: {
_29
progress: 1,
_29
urls: [
_29
"https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZnZoMndsdWh0MmhvY2kyaDF6YjZjZzg1ZGsxdnhhYm13a3Q1Y3lkbyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/13HgwGsXF0aiGY/giphy.gif",
_29
],
_29
},
_29
});
_29
},
_29
});

Check out React Status Hooks in the docs.