Jobs - Output type error following the example in docs
Hey guys! I'm following the docs on how to create a job (https://wasp-lang.dev/docs/advanced/jobs#job-definition-and-usage). Unfortunately, I'm having some type errors. I'm using openSaas template.
Error:
Is there some issue with the example that I missed?
Thank you for your help!
Recurring Jobs | Wasp
In most web apps, users send requests to the server and receive responses with some data. When the server responds quickly, the app feels responsive and smooth.
23 Replies
Hey 👋 Have you tried mapping the tasks array into an array of objects with properties you need? If you could be so kind to try this.
I'm not sure if the issue is that Prisma's objects are not serializable or we actually have bug.
Hey @miho ! I tried mocking the output completely, with a valid output, but it still complains.
If I set the output type as string, it doesn't complain anymore
Wohooo @kancur, you just became a Waspeteer level 1!
So there's something about the
Task
type, that doesn't workSo as a workaround, I can create a custom type and return that instead of prismas type directly, I guess.
It seems the
createdAt
field is an issue - when I omit it, it works.nope, it doesn't actually work, I no longer see the error in vscode, but it doesn't compile 😦
Hmmmm that's weird. I guess the issue is that the
Task
is a class with methods and stuff, have you maybe tried what you said, creating new objects with only the fields you need? e.g.
tried it, doesn't help
full error for reference (above)
Here's my task model:
It's basically the
OpenSaas
template + copy pasting that jobs code from the docsOkay, I now know why it worked in docs 🙂 The Task entity is much simpler there, and doesn't contain date
Wohooo @kancur, you just became a Waspeteer level 2!
if it contained value typed Date, it would throw typescript error like mine I think 🙂
Gotcha! Okay, so what's going on here:
1. We are using PgBoss for our async jobs processing
2. PgBoss saves the output of a job in a Postgres database (using a JSON field FYI)
3. PgBoss expects from us to save job outputs as plain objects (
Date
is a class, not a primitive value like string
) which means you can't save really any object you want
4. Ideally, you would save to the database only objects with primitive values, but values you can use to reference the actual task like e.g. Task.id
What I would recommend, make the Output
more primitive e.g. { id: 5 }
and then when you need the tasks, fetch them using the saved IDsOkay, I see now! 🙂 Thanks for your help & tips @miho !
Thank you for the patience and making us figure this out! 🙂
We could improve our jobs output serialization e.g. use Superjson which can handle dates, which would make your experience smoother. Good thing for us to note.