Warning: Advanced Topic
Using external queues is an advanced topic and is not recommended for beginners. You should only attempt this if you feel comfortable with the following docs.
In Joystick, external queues are used to split work across multiple apps. For example, you may have one app that is your main user-facing app and another Joystick app that functions as a job server.
By marking a queue as external: true
, Joystick allows both apps to add jobs to the same database queue, while only one app (the job server) is responsible for running those jobs. This approach avoids wiring up HTTP routes between apps and simplifies scaling.
Example Usage
User-Facing App: Marking a Queue as External
/index.server.js
import joystick from '@joystick.js/node';
joystick.app({
queues: {
encoder: {
external: true,
},
},
routes: { ... },
});
User-Facing App: Database Configuration
/settings.development.json
{
"config": {
"databases": [
{
"provider": "mongodb",
"users": true,
"queues": true,
"options": {}
}
],
...
},
"global": {},
"public": {},
"private": {}
}
Job Server App: Defining the Queue
/index.server.js
import joystick from '@joystick.js/node';
joystick.app({
queues: {
encoder: {
run_on_startup: true,
concurrent_jobs: 10,
jobs: {
encode_image: {
run: (payload = {}, job = {}) => {
// Handle work for the job here...
},
},
},
},
},
routes: { ... },
});
Job Server App: Database Configuration
/settings.development.json
{
"config": {
"databases": [
{
"provider": "mongodb",
"queues": true,
"options": {},
"connection": {
"username": "",
"password": "",
"database": "app",
"hosts": [
{
"hostname": "127.0.0.1",
"port": 2610
}
]
}
}
],
...
},
"global": {},
"public": {},
"private": {}
}
User-Facing App: Adding a Job to an External Queue
/index.server.js
import joystick from '@joystick.js/node';
joystick.app({
queues: {
encoder: {
external: true,
},
},
routes: { ... },
}).then(async () => {
await process.queues.encoder.add({
job: 'encode_image',
next_run_at: new Date().toISOString(),
payload: {
image_url: '...',
},
});
});