Comparing version 0.0.30 to 0.0.31
@@ -34,5 +34,6 @@ 'use strict' | ||
this.onRollbackHooks = [] | ||
this.onTaskRollbackHooks = [] | ||
this.onTaskEndHooks = [] | ||
this.onTaskStartHooks = [] | ||
this.onRollbackFinishHooks = [] | ||
} | ||
@@ -89,4 +90,69 @@ /** | ||
* | ||
* @param {any} fn | ||
* @memberof Pipeline | ||
*/ | ||
onDrain(fn) { | ||
if (typeof fn !== 'function') { | ||
throw new TypeError('The Hook handler must be a function') | ||
} | ||
this.queue.drain(fn) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} fn | ||
* @memberof Pipeline | ||
*/ | ||
onTaskStart(fn) { | ||
if (typeof fn !== 'function') { | ||
throw new TypeError('The Hook handler must be a function') | ||
} | ||
this.onTaskStartHooks.push(fn) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} fn | ||
* @memberof Pipeline | ||
*/ | ||
onTaskEnd(fn) { | ||
if (typeof fn !== 'function') { | ||
throw new TypeError('The Hook handler must be a function') | ||
} | ||
this.onTaskEndHooks.push(fn) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} fn | ||
* @memberof Pipeline | ||
*/ | ||
onTaskRollback(fn) { | ||
if (typeof fn !== 'function') { | ||
throw new TypeError('The Hook handler must be a function') | ||
} | ||
this.onTaskRollbackHooks.push(fn) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} fn | ||
* @memberof Pipeline | ||
*/ | ||
onRollbackFinish(fn) { | ||
if (typeof fn !== 'function') { | ||
throw new TypeError('The Hook handler must be a function') | ||
} | ||
this.onRollbackFinishHooks.push(fn) | ||
} | ||
/** | ||
* | ||
* | ||
* @memberof Pipeline | ||
*/ | ||
async rollback() { | ||
@@ -104,3 +170,3 @@ if (this.rollbacking) { | ||
let state = new State(this.queue, task, this) | ||
for (let hook of this.onRollbackHooks) { | ||
for (let hook of this.onTaskRollbackHooks) { | ||
if (hook instanceof Task) { | ||
@@ -112,2 +178,3 @@ await state.addTask(hook, state) | ||
} | ||
await task.executeRollback(state) | ||
@@ -124,2 +191,6 @@ } catch (err) { | ||
for (let hook of this.onRollbackFinishHooks) { | ||
await hook() | ||
} | ||
this.rollbacking = false | ||
@@ -157,2 +228,3 @@ } | ||
debug(`Starting rollback after restore`) | ||
await this.rollback() | ||
@@ -165,29 +237,2 @@ | ||
* | ||
* @param {any} fn | ||
* @memberof Pipeline | ||
*/ | ||
onTaskStart(fn) { | ||
this.onTaskStartHooks.push(fn) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} fn | ||
* @memberof Pipeline | ||
*/ | ||
onTaskEnd(fn) { | ||
this.onTaskEndHooks.push(fn) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} fn | ||
* @memberof Pipeline | ||
*/ | ||
onRollback(fn) { | ||
this.onRollbackHooks.push(fn) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} task | ||
@@ -204,5 +249,5 @@ * @param {any} state | ||
await task.executeHooks('onInit', state) | ||
// mark task as initialized so it can be filtered for rollback and restore | ||
task.initialized = true | ||
await task.executeHooks('onInit', state) | ||
} | ||
@@ -217,2 +262,8 @@ /** | ||
async executeTask(task, state) { | ||
// execute task only when we are in rollback mode or no error was occured | ||
if (this.error && !this.rollbacking) { | ||
debug(`Abort task due to pipeline error`) | ||
return | ||
} | ||
for (let hook of this.onTaskStartHooks) { | ||
@@ -227,2 +278,4 @@ await hook.call(task, state) | ||
const result = await task.action(state) | ||
// mark task as initialized so it can be filtered for rollback and restore | ||
task.run = true | ||
if (result && typeof task.validateResult === 'function') { | ||
@@ -272,4 +325,4 @@ await task.validateResult(result) | ||
for (let task of this.registry.tasks) { | ||
if (this.rollbacking) { | ||
error('Abort Pipeline error %O', this.error) | ||
if (this.error) { | ||
error('Abort task due to pipeline error %O', this.error) | ||
break | ||
@@ -287,3 +340,3 @@ } | ||
this.results.set(`${task.name}:error`, err) | ||
await this.rollback(state) | ||
await this.rollback() | ||
} | ||
@@ -290,0 +343,0 @@ }) |
@@ -50,3 +50,3 @@ 'use strict' | ||
*/ | ||
validateConfig(value) { | ||
async validateConfig(value) { | ||
return value | ||
@@ -85,18 +85,12 @@ } | ||
if (result) { | ||
if (result.error) { | ||
error( | ||
`Task <${this.constructor.name}:${this | ||
.name}> Invalid config schema. Error: %O`, | ||
result.error | ||
) | ||
throw new Error( | ||
`Task <${this.constructor.name}:${this | ||
.name}> has an innvalid config schema. ${result.error.message}` | ||
) | ||
} else if (result.value) { | ||
this.config = result.value | ||
} else if (config) { | ||
this.config = config | ||
} | ||
if (result && typeof result.then === 'function') { | ||
return result.then(c => { | ||
this.config = Object.assign(c, this.config) | ||
}) | ||
} else if (typeof result === 'object') { | ||
this.config = Object.assign(result, config, this.config) | ||
} else { | ||
throw new Error( | ||
'Respond with an invalid config construct' | ||
) | ||
} | ||
@@ -103,0 +97,0 @@ } |
{ | ||
"name": "bootme", | ||
"version": "0.0.30", | ||
"version": "0.0.31", | ||
"description": "", | ||
@@ -30,9 +30,8 @@ "main": "index.js", | ||
"debug": "^3.1.0", | ||
"workq": "^1.1.1" | ||
"workq": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^3.0.0", | ||
"delay": "^2.0.0", | ||
"tap": "^10.7.2" | ||
"tap": "^10.7.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
305271
2
725
Updatedworkq@^1.2.0