W
Wasp-lang5mo ago
mb23

Issue with creating jobs/workers

I want to create jobs/workers for functions that use external APIs such as OpenAI so they're also processed if the user closes/refrehes the page. Example: For an outline creation function I have created: 1) a job definition in the main.wasp: job createOutlineJob { executor: PgBoss, perform: { fn: import { createOutlineWorker } from "@src/server/workers/outlineWorker" }, entities: [User, Keyword, Headline, Websites] } 2) an OutlineWorker,ts file in ..\app\src\server\workers that contains all helper functions for the main createOutlineWorker function and of course the createOutlineWorker function itself: export const createOutlineWorker: CreateOutlineJob<Input, Output> = async ({ keywordId }, context) => { 3) reference on an app page: import { createOutlineJob } from 'wasp/server/jobs'; ... const handleCreateOutline = async (keywordId) => { try { await createOutlineJob.submit({ keywordId: keywordId }); } catch (error) { console.error('Failed to enqueue createOutlineJob:', error); } }; Still, I get this error and a blank page when i try to build: ReferenceError: process is not defined at config.ts:41:20 I've already read that this seems to be server code that's loaded in the client but having a hard time to figure out what to do about it :/
6 Replies
kapa.ai
kapa.ai5mo ago
Hi @mb23. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The error message ReferenceError: process is not defined typically occurs when server-side code is being executed in the client context. This could be due to the fact that some part of your code that was previously executed in the server context is now being executed in the client context. In your case, it seems like the error is coming from config.ts inside the sdk folder. This could be due to the fact that the file is not able to access your .env.server file. Please ensure that the .env.server file is in the correct place, which should be inside the app folder. If you have not modified the contents of the .wasp folder, i.e., the sdk folder, you could try executing wasp clean and then a fresh wasp start to see if the error persists. If the error still persists, you could try adding PORT=3001 to your .env.server file. If that fixes it, then somehow your app is picking up that you're not in the development environment. If none of the above solutions work, it would be helpful if you could share more information about the error. Ideally, a reproducible example that we can try running ourselves would be most helpful. If that is too hard to obtain, then maybe sharing some specifics of your app would be beneficial. Also, please ensure that you are not importing anything from wasp/server/* on the client. If you are getting this error in the browser, this means something that should be only used on server is being used on the client. Lastly, you could check your code for any TODOs that have to do with the recent migration. There might be some server code being executed in the client somewhere, and if we can find where that's happening we can fix the problem. Sources: - Discord support thread: Error building after migrating Wasp to 0.12 > Answers Part 1 (https://discord.com/channels/686873244791210014/1212533517360177253) - Discord support thread: Error building after migrating Wasp to 0.12 > Answers Part 2 (https://discord.com/channels/686873244791210014/1212533517360177253) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @mb23, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
mb23
mb23OP5mo ago
I'm loading the createOutlineJob function in my app client page: import { createOutlineJob } from 'wasp/server/jobs'; Is this wrong? How should i import the worker function instead?
MEE6
MEE65mo ago
Wohooo @mb23, you just became a Waspeteer level 3!
mb23
mb23OP5mo ago
@kapa.ai
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @mb23, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho5mo ago
I'd advise going through the Wasp tutorial to get familiar with the Wasp basics: https://wasp-lang.dev/docs/tutorial/create Then I'd check the docs on Jobs: https://wasp-lang.dev/docs/advanced/jobs In short, you don't import jobs (backend code) in your client code. You either call them from your backend code (actions, custom APIs) or make them recurring so they run automatically. Here's an example app using jobs (notice we are calling jobs in the server context): https://github.com/wasp-lang/lazy-card-generator/blob/main/src/cards/index.ts#L143
1. Creating a New Project | Wasp
You'll need to have the latest version of Wasp installed locally to follow this tutorial. If you haven't installed it yet, check out the QuickStart guide!
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.
GitHub
lazy-card-generator/src/cards/index.ts at main · wasp-lang/lazy-car...
Demonstration of Wasp and Supabase working together, using Llama 3 and SDXL to generate greeting cards! - wasp-lang/lazy-card-generator
Want results from more Discord servers?
Add your server