In order for a queue to run, it needs to be registered with your app. To register it, define the queue on the queues
object passed as part of the options
object to joystick.app()
.
Example Usage
Defining a Queue Inline
/index.server.js
import joystick from '@joystick.js/node';
joystick.app({
queues: {
example: {
run_on_startup: true,
concurrent_jobs: 10,
jobs: {
example_job: {
run: (payload = {}, job = {}) => {
// Handle work for the job here...
// Call one of job.completed(), job.failed(), job.requeue(), or job.delete(), after work is finished.
},
},
},
},
},
routes: { ... }
});
Defining a Queue in a Separate File
/queues/example.js
const example_queue = {
run_on_startup: true,
concurrent_jobs: 10,
jobs: {
example_job: {
run: (payload = {}, job = {}) => {
// Handle work for the job here...
// Call one of job.completed(), job.failed(), job.requeue(), or job.delete(), after work is finished.
},
},
},
};
export default example_queue;
Centralizing Queue Definitions
/queues/index.js
import example from './example.js';
const queues = {
example,
};
export default queues;
Registering Queues in joystick.app()
/index.server.js
import joystick from '@joystick.js/node';
import queues from './queues/index.js';
joystick.app({
queues,
routes: { ... }
});