Trouble setting up a cron job
I'm trying to set up a cron job, but I'm getting an odd error message:
From a working version, all I did was:
main.wasp:
src/workers/bar:
And in actions.ts:
17 Replies
Hi @ArjunSohur. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the error message you provided, it seems like the issue is related to the import of the
actions
directory. The error message Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/app/.wasp/out/sdk/wasp/dist/client/operations/actions' is not supported resolving ES modules imported from /app/.wasp/out/sdk/wasp/dist/client/operations/index.js
suggests that there might be a problem with how the actions
are being imported or used.
In your actions.ts
file, you are trying to import makeNewsletters
from 'wasp/server/jobs'
and then calling makeNewsletters.submit({})
. However, based on the information provided, it's not clear if makeNewsletters
is correctly exported from 'wasp/server/jobs'
or if the submit
method is correctly defined.
Also, it's worth noting that in your main.wasp
file, you are importing doAll
from "@src/workers/bar"
. Make sure that doAll
is correctly exported from bar.js
file.
Here is an example of how to declare a job in Wasp:
(Source: Wasp Docs (https://wasp-lang.dev/docs/advanced/jobs#declaring-jobs))
If the issue persists, it might be helpful to seek support from the Wasp community or the Wasp team directly. They might be able to provide more specific guidance based on the exact configuration and code of your project.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ArjunSohur, 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?@kapa.ai It's an odd error because this is the file that it's yelling at me about:
Which I can't detect any errors in. It's also odd that only when I put a job in wasp.main and make the workers/bar.ts does it complain.
Let me check the knowledge base for you. One moment! :books:
----------------------
The error message you're seeing is related to ES Modules in Node.js. The error
ERR_UNSUPPORTED_DIR_IMPORT
is thrown when you're trying to import a directory instead of a specific module. In ES Modules, unlike in CommonJS, importing directories is not supported.
In your code, you're exporting everything from the actions
and queries
directories:
This is likely what's causing the error. You should instead import specific modules from these directories. If you have an index.js
(or index.ts
for TypeScript) file in these directories that re-exports all the modules, you can import that instead.
For example, if you have actions/index.js
and queries/index.js
, you can do:
This way, you're not importing the directories themselves, but the index.js
files that re-export all the modules.
If the issue persists, it might be helpful to seek support from the Wasp community or the Wasp team directly. They might be able to provide more specific guidance based on the exact configuration and code of your project.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ArjunSohur, 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?@kapa.ai Since this is in .wasp, I have no control over the actual code itself since it rebuilds itself every time.
And I've also tried wasp clean.
Let me check the knowledge base for you. One moment! :books:
----------------------
I see, if the problematic code is in the
.wasp
directory, it's indeed generated by Wasp and not directly controllable.
The issue you're experiencing seems to be related to the way Wasp handles file changes and rebuilds the application. There are some discussions and open issues in the Wasp community that indicate similar problems:
- In a Discord thread (https://discord.com/channels/686873244791210014/1223304305206099969), users reported that the application reloads and rebuilds after every UI change, which can be disruptive and cause issues in certain scenarios.
- An open issue on GitHub (https://github.com/wasp-lang/wasp/issues/1844) discusses the need to investigate how file watching and hot reloading work in Wasp, especially after the restructuring in Wasp 0.12.0.
Unfortunately, based on the provided knowledge sources, there isn't a clear solution to your problem. It might be a bug or a limitation in the current version of Wasp.
I recommend reaching out to the Wasp community or the Wasp team directly for further assistance. You can share the details of your issue, and they might be able to provide a workaround or fix.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ArjunSohur, 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?yikes
Does
src/workers/bar
have an extension?Yes, it's a .ts
I'm following this: https://wasp-lang.dev/docs/advanced/jobs
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.
I see
wasp/client/operations
import on the server? That's not supported, it should be wasp/server/operations
That's a good catch, but unfortunately it didn't fix it.
Here's the error again, if it's any help:
I'm going to try resetting and doing it over again, though I've already done that.
Ok, I've messed around a little and gotten a new error.
This time, I'm not being over zealous and I'm just seeing if I can get a job of sorts running.
In sendNewsletters.ts (premade file):
In main.wasp:
This complies, but when I add
in actions.ts, I get no error message, but the wasp docker container crashes:
wasp-server-1 exited with code 13
@kapa.ai Maybe you can help here?
Let me check the knowledge base for you. One moment! :books:
----------------------
The error you're encountering seems to be related to the way you're trying to submit the job in
actions.ts
.
In Wasp, jobs are submitted using the submit
method, which takes an argument that is passed to the job handler function. This argument should match the Input
type of your job handler function. In your case, you've defined the Input
type as never
, which means it should never receive any arguments. However, you're trying to submit the job with an empty object {}
as an argument, which could be causing the issue.
Here's how you can submit a job in Wasp:
(Source: Wasp Docs (https://wasp-lang.dev/docs/advanced/jobs#javascript-api))
In your case, since you've defined the Input
type as never
, you should submit the job without any arguments:
If the issue persists, it might be helpful to seek support from the Wasp community or the Wasp team directly. They might be able to provide more specific guidance based on the exact configuration and code of your project.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ArjunSohur, 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?Yeah, sorry Kapa, that didn't work, wasp will complain if I don't pass anything into submit.
Wohooo @ArjunSohur, you just became a Waspeteer level 3!
So in general, I'm having trouble running the job rather than declaring the job
Hey @ArjunSohur, can you maybe share the code that reproduces the error (an app in a zip file) so I can get into it as quickly as possible?
@sodic So it turns out I didn't rtfm carefully enough...
There was really never any problem, I just didn't understand how cron worked 🥲