queue
How can I send a message to a queue ( for background processing) in a Wasp application?
2 Replies
Hi @Karma Andrew. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To send a message to a queue for background processing in a Wasp application, you should use Wasp's Jobs feature. Here’s how you can do it:
1. Declare a Job in your
Define a job and specify the function that should be executed in the background. For example: This sets up a job called
In your worker file (e.g.,
In your server-side code (e.g., an Action or another server function), import the job and submit it: The
- Declare a job in your
.wasp
fileDefine a job and specify the function that should be executed in the background. For example: This sets up a job called
mySpecialJob
that will use the foo
function from your worker file for processing. The executor PgBoss
is currently the only supported job executor and uses PostgreSQL as the backend queue system. The entities
field allows you to specify which entities are available in the job context, if needed for database access Declaring Jobs.
2. Implement the Worker FunctionIn your worker file (e.g.,
src/workers/bar.js
), implement the function that will process the job:
The function receives the job arguments and a context object with access to your entities Job Definition and Usage.
3. Submit a Job to the QueueIn your server-side code (e.g., an Action or another server function), import the job and submit it: The
.submit()
method sends the job to the queue for background processing. You can also use .delay()
to schedule the job for future execution JavaScript API.
Summary:- Declare a job in your
.wasp
file.
- Implement the worker function.
- Use .submit()
(and optionally .delay()
) to send a message to the queue for background processing.
Wasp jobs are persistent, can be retried, delayed, or scheduled, and are suitable for typical background processing tasks in web applications Recurring Jobs.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Karma Andrew, 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?We don't support queues as a wasp feature, rather you need to implement it yourself like in any other project.
You can do it in postgres or use something separate (redis, rabbitmq...).