-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from adhocteam/cm-204-add-file-queue
Cm 204 add file queue components to backend app
- Loading branch information
Showing
9 changed files
with
220 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 13. Add job queue and worker | ||
|
||
# Date | ||
20201-02-13 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
In order to satisfy the [RA-5](https://nvd.nist.gov/800-53/Rev4/control/RA-5) | ||
control around vulnerability scanning, we wish to scan all user-uploaded files | ||
with a malware detection service. We want to satisfy the following requirements. | ||
1. Scanning can be done asyncronously so as not to negatively impact the user experience. | ||
2. Scanning should be loosely coupled to main application to allow for more resiliance and fault tolerance. | ||
3. Scanning should be retried if malware detection service is unavailable. | ||
4. Scanning should run on a seperate instance to prevent a negative impact to the user experience. | ||
|
||
## Decision | ||
|
||
We will use redis as a queue and build a worker node which will take jobs from the queue, send them to the malware detection service and then update the database with the scan results. | ||
|
||
## Consequences | ||
|
||
All of the above requirements are filled. This does introduce some additional complexity in the form of a redis instance and worker instance. However, cloud.gov supplies managed redis instances and the worker will be built on top of an official node.js buildpack, so any additional maintenance from running these instances is negligable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/migrations/20210215161922-add-statuses-to-file-model.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
up: async (queryInterface) => { | ||
await queryInterface.sequelize.query('ALTER TYPE "enum_Files_status" ADD VALUE \'QUEUEING_FAILED\';'); | ||
await queryInterface.sequelize.query('ALTER TYPE "enum_Files_status" ADD VALUE \'SCANNING_QUEUED\';'); | ||
}, | ||
down: async (queryInterface) => { | ||
let query = 'DELETE FROM pg_enum WHERE enumlabel = \'QUEUEING_FAILED\' AND enumtypid = ( SELECT oid FROM pg_type WHERE typname = \'enum_Files_status\')'; | ||
await queryInterface.sequelize.query(query); | ||
query = 'DELETE FROM pg_enum WHERE enumlabel = \'SCANNING_QUEUED\' AND enumtypid = ( SELECT oid FROM pg_type WHERE typname = \'enum_Files_status\')'; | ||
await queryInterface.sequelize.query(query); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Queue from 'bull'; | ||
|
||
const REDIS_PORT = process.env.REDIS_PORT || 6379; | ||
const { REDIS_HOST, REDIS_PASS } = process.env; | ||
|
||
const scanQueue = new Queue('scan', `redis://${REDIS_HOST}:${REDIS_PORT}`, { redis: { password: REDIS_PASS } }); | ||
|
||
export default async function addToScanQueue(fileKey) { | ||
await scanQueue.add(fileKey); | ||
} |
Oops, something went wrong.