Skip to content

Instantly share code, notes, and snippets.

View PatrickKalkman's full-sized avatar
🏠
Working from home

Patrick Kalkman PatrickKalkman

🏠
Working from home
View GitHub Profile
.
├── AssetStorage
├── Encoder
├── Packager
├── WorkflowAdmin
├── WorkflowDatabase
│ └── data
│ └── workflow-db.db
└── WorkflowEngine
@PatrickKalkman
PatrickKalkman / jobRoutes.js
Created January 11, 2020 10:05
Routes definition for Fastify using fastify-register-routes
const jobController = require('../controllers/jobController');
const jobRoutes = [
{
name: 'GetJobs',
method: 'get',
path: '/api/jobs',
handler: jobController.getJobs,
},
{
const mongoose = require('mongoose');
const jobSchema = new mongoose.Schema({
name: { type: String, required: true },
encodingType: { type: String, required: true },
inputFolder: { type: String, required: true },
inputAsset: { type: String, required: true },
outputFolder: { type: String, required: true },
outputAsset: { type: String, required: true },
status: { type: String, required: false },
@PatrickKalkman
PatrickKalkman / jobController.js
Created January 11, 2020 16:01
Part of the JobController that saves a job using Mongoose
jobController.addJob = function addJob(req, reply) {
const job = new Job(req.body);
job.status = constants.WORKFLOW_STATUS.NEW;
job.save(function(err, job) {
if (!err) {
reply.send(job);
} else {
reply.badRequest(err);
}
});
jobController.getJob = function getJob(req, reply) {
const id = req.params.id;
Job.findById(id, function(err, job) {
if (!err) {
if (job) {
reply.send(job);
} else {
reply.notFound(`Could not find job with id ${id}`);
}
} else {
@PatrickKalkman
PatrickKalkman / jobController.js
Created January 11, 2020 19:58
Update part of the JobController
jobController.updateJob = function updateJob(req, reply) {
const id = req.params.id;
const job = req.body;
const { ...updateData } = job;
Job.findByIdAndUpdate(id, updateData, { new: true }, function(err, job) {
if (!err) {
if (job) {
reply.send(job);
} else {
reply.notFound(`Could not find job with id ${id}`);
FROM node:12-alpine
EXPOSE 8181
HEALTHCHECK --interval=17s --timeout=3s --start-period=5s \
CMD node ./lib/healthcheck.js
# Create the work dir and set permissions as WORKDIR set the permissions as root
RUN mkdir /home/node/app/ && chown -R node:node /home/node/app
@PatrickKalkman
PatrickKalkman / docker-compose.yml
Created January 12, 2020 13:45
Docker compose file to start the WorkflowEngine and the WorkflowDatabase
version: '2'
services:
workflowdb:
image: 'mongo:4.0.14'
container_name: 'workflow-db'
environment:
- MONGO_INITDB_ROOT_USERNAME=mveroot
- MONGO_INITDB_ROOT_PASSWORD=2020minivideoencoder!
- MONGO_INITDB_DATABASE=workflow-db
volumes:
@PatrickKalkman
PatrickKalkman / response.json
Created January 12, 2020 18:24
API response when required field is missing
{
"statusCode": 400,
"error": "Bad Request",
"message": "ValidationError: outputAsset: Path `outputAsset` is required."
}
{
name: 'GetJobs', // Optional name for convenience
method: 'get', // The HTTP verb to use
path: '/api/jobs', // The path of the route
handler: jobController.getJobs, // The controller method to call
}