From b6fcbf0559bac7f311535e6e560b96658acca9bc Mon Sep 17 00:00:00 2001 From: scott-wyatt Date: Thu, 6 Sep 2018 16:44:51 -0400 Subject: [PATCH] [fix] config schema --- README.md | 4 +-- lib/TasksSpool.ts | 12 +++++++++ lib/config/tasks.ts | 20 +++++++------- lib/schemas/tasksConfig.ts | 22 +++++++-------- package.json | 2 +- test/fixtures/app.js | 39 ++++++++++++++------------- test/integration/tasks/Rabbit.test.js | 1 + 7 files changed, 58 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 337570e..74f1dfb 100755 --- a/README.md +++ b/README.md @@ -66,10 +66,10 @@ export const tasks = { }, /** - * Set worker to subscribe to tasks in the matching profile (tasker.profiles). + * Set worker to subscribe to tasks in the matching profile (tasks.profiles). * If process.env.WORKER does not match a profile, the application will not subscribe to any tasks */ - worker: process.env.WORKER + profile: process.env.WORKER } ``` diff --git a/lib/TasksSpool.ts b/lib/TasksSpool.ts index f7e633f..d03f8af 100755 --- a/lib/TasksSpool.ts +++ b/lib/TasksSpool.ts @@ -56,6 +56,9 @@ export class TasksSpool extends ExtensionSpool { return Promise.all([ Validator.validateTasksConfig(this.app.config.get('tasks')) ]) + .catch(err => { + return Promise.reject(err) + }) } /** @@ -68,6 +71,9 @@ export class TasksSpool extends ExtensionSpool { Tasks.buildTasker(this.app), Tasks.copyDefaults(this.app) ]) + .catch(err => { + return Promise.reject(err) + }) } /** @@ -77,6 +83,9 @@ export class TasksSpool extends ExtensionSpool { return Promise.all([ Tasks.addTasks(this.app) ]) + .catch(err => { + return Promise.reject(err) + }) } /** @@ -86,5 +95,8 @@ export class TasksSpool extends ExtensionSpool { return Promise.all([ Tasks.shutdownTasker(this.app) ]) + .catch(err => { + return Promise.reject(err) + }) } } diff --git a/lib/config/tasks.ts b/lib/config/tasks.ts index cfc1305..0d345a7 100755 --- a/lib/config/tasks.ts +++ b/lib/config/tasks.ts @@ -7,31 +7,31 @@ export const tasks = { prefix: null, live_mode: true, auto_save: false, - profile: process.env.ENGINE_PROFILE || null, + profile: process.env.TASKS_PROFILE || null, enabled: true, auto_queue: true, connection: { // optional, defaults to `tasks-work-x` - exchange: process.env.ENGINE_TASK_EXCHANGE, + exchange: process.env.TASKS_EXCHANGE || null, // optional, defaults to `tasks-work-q` - work_queue_name: process.env.ENGINE_TASK_WORK_QUEUE, + work_queue_name: process.env.TASKS_WORK_QUEUE || null, // optional, defaults to `tasks-interrupt-q` - interrupt_queue_name: process.env.ENGINE_TASK_INTERRUPT_QUEUE, + interrupt_queue_name: process.env.TASKS_INTERRUPT_QUEUE || null, /** * The RabbitMQ connection information. * See: https://www.rabbitmq.com/uri-spec.html */ - host: process.env.ENGINE_TASK_RMQ_HOST, - user: process.env.ENGINE_TASK_RMQ_USER, - pass: process.env.ENGINE_TASK_RMQ_PASS, - port: process.env.ENGINE_TASK_RMQ_PORT, - vhost: process.env.ENGINE_TASK_RMQ_VHOST, + host: process.env.TASKS_RMQ_HOST || null, + user: process.env.TASKS_RMQ_USER || null, + pass: process.env.TASKS_RMQ_PASS || null, + port: process.env.TASKS_RMQ_PORT || null, + vhost: process.env.TASKS_RMQ_VHOST || null, /** * Connection information could also be passed via uri */ - uri: process.env.RMQ_URI, + uri: process.env.TASKS_RMQ_URI || null, /** * Additional, optional connection options (default values shown) diff --git a/lib/schemas/tasksConfig.ts b/lib/schemas/tasksConfig.ts index 935327b..d8ade66 100755 --- a/lib/schemas/tasksConfig.ts +++ b/lib/schemas/tasksConfig.ts @@ -9,20 +9,20 @@ export const tasksConfig = joi.object().keys({ auto_queue: joi.boolean(), // profiles: joi.object().pattern(/^/, joi.array().items(joi.string().regex(/(.+)\.(.+)/))), profiles: joi.object().pattern(/^/, joi.array().items(joi.string())), - exchange_name: joi.string().allow('', null), + exchange_name: joi.string().allow(null), connection: joi.object().keys({ - exchange: joi.string().allow('', null), - work_queue_name: joi.string().allow('', null), - interrupt_queue_name: joi.string().allow('', null), - host: joi.string().allow('', null), - user: joi.string().allow('', null), - pass: joi.string().allow('', null), - port: joi.number().allow('', null), - vhost: joi.string().allow('', null), - uri: joi.string().allow('', null), + exchange: joi.string().allow(null), + work_queue_name: joi.string().allow(null), + interrupt_queue_name: joi.string().allow(null), + host: joi.string().allow(null), + user: joi.string().allow(null), + pass: joi.string().allow(null), + port: joi.number().allow(null), + vhost: joi.string().allow(null), + uri: joi.string().allow(null), heartbeat: joi.number(), timeout: joi.number().allow(null), failAfter: joi.number(), retryLimit: joi.number() - }) + }).unknown() }) diff --git a/package.json b/package.json index ee0cbc3..89fee7b 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-tasks", - "version": "1.1.2", + "version": "1.1.3", "description": "Spool - Emitter Engine for Fabrix", "homepage": "https://fabrix.app", "author": { diff --git a/test/fixtures/app.js b/test/fixtures/app.js index ea10608..1c5cf17 100755 --- a/test/fixtures/app.js +++ b/test/fixtures/app.js @@ -89,24 +89,27 @@ const App = { ] }, connection: { - // exchange: process.env.TASK_EXCHANGE, // optional, defaults to `tasks-work-x` - // work_queue_name: process.env.TASK_WORK_QUEUE, // optional, defaults to `tasks-work-q` - // interrupt_queue_name: process.env.TASK_INTERRUPT_QUEUE, // optional, defaults to `tasks-interrupt-q` - // - // /** - // * The RabbitMQ connection information. - // * See: https://www.rabbitmq.com/uri-spec.html - // */ - // // host: process.env.TASK_RMQ_HOST, - // // user: process.env.TASK_RMQ_USER, - // // pass: process.env.TASK_RMQ_PASS, - // // port: process.env.TASK_RMQ_PORT, - // // vhost: process.env.TASK_RMQ_VHOST, - // - // /** - // * Connection information could also be passed via uri - // */ - // uri: process.env.RMQ_URI || 'amqp://', + // optional, defaults to `tasks-work-x` + exchange: process.env.TASKS_EXCHANGE, + // optional, defaults to `tasks-work-q` + work_queue_name: process.env.TASKS_WORK_QUEUE, + // optional, defaults to `tasks-interrupt-q` + interrupt_queue_name: process.env.TASKS_INTERRUPT_QUEUE, + + /** + * The RabbitMQ connection information. + * See: https://www.rabbitmq.com/uri-spec.html + */ + host: process.env.TASKS_RMQ_HOST, + user: process.env.TASKS_RMQ_USER, + pass: process.env.TASKS_RMQ_PASS, + port: process.env.TASKS_RMQ_PORT, + vhost: process.env.TASKS_RMQ_VHOST, + + /** + * Connection information could also be passed via uri + */ + uri: process.env.TASKS_RMQ_URI, /** * Additional, optional connection options (default values shown) diff --git a/test/integration/tasks/Rabbit.test.js b/test/integration/tasks/Rabbit.test.js index 32acdd6..af294ff 100644 --- a/test/integration/tasks/Rabbit.test.js +++ b/test/integration/tasks/Rabbit.test.js @@ -28,6 +28,7 @@ describe('Rabbit', () => { }) it('should have tasker on app', () => { + console.log('BROKE', global.app.config.get('tasks')) assert.ok(global.app.tasker) assert.equal(global.app.callCount, 0) assert.equal(global.app.finalizeCount, 0)