Skip to content

Commit

Permalink
Merge pull request #3 from fabrix-app/v1.1
Browse files Browse the repository at this point in the history
[fix] config schema
  • Loading branch information
scott-wyatt authored Sep 6, 2018
2 parents 9d05df2 + b6fcbf0 commit b52c58c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down
12 changes: 12 additions & 0 deletions lib/TasksSpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

/**
Expand All @@ -68,6 +71,9 @@ export class TasksSpool extends ExtensionSpool {
Tasks.buildTasker(this.app),
Tasks.copyDefaults(this.app)
])
.catch(err => {
return Promise.reject(err)
})
}

/**
Expand All @@ -77,6 +83,9 @@ export class TasksSpool extends ExtensionSpool {
return Promise.all([
Tasks.addTasks(this.app)
])
.catch(err => {
return Promise.reject(err)
})
}

/**
Expand All @@ -86,5 +95,8 @@ export class TasksSpool extends ExtensionSpool {
return Promise.all([
Tasks.shutdownTasker(this.app)
])
.catch(err => {
return Promise.reject(err)
})
}
}
20 changes: 10 additions & 10 deletions lib/config/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions lib/schemas/tasksConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
39 changes: 21 additions & 18 deletions test/fixtures/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/integration/tasks/Rabbit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b52c58c

Please sign in to comment.