RFCx Core API - Tasks
January 17, 2022 ยท View on GitHub
Home | Tasks | Build/Deployment
RFCx Core API - Tasks
Introduction
Core Tasks are background processes that listen to message queues for events and perform (potentially long-running) tasks when an event occurs. The motivation for tasks is to avoid blocking http requests to the API. Use cases:
- Send notifications to rangers when a chainsaw alert is created
- Create a thumbnail image when a new image is uploaded
- Find all the enabled classifiers for a stream and queue for processing when a segment is added to a stream
Running locally
- Use
docker-compose up -dto start the local SQS server (as well as the database). - Ensure the env_vars are set for
MESSAGE_QUEUE_*(ENDPOINTshould be localhost or your docker machine IP). - Run
npm run dev:tasksto start the Tasks server (with hot-reloading).
Adding a new task
- Define an event name in
event-names.js - Publish to
MessageQueue.default()when the event occurs - Create a new folder in the current directory for the task. Write a task handler to run when the event occurs.
- Import the event name and the task handler in
listen.jsand add to the list oftasks.