@wmfs/statebox
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -204,21 +204,12 @@ 'use strict' | ||
sendTaskHeartbeat (executionName, options, executionOptions, callback) { | ||
this.options.dao.findExecutionByName( | ||
executionName, | ||
function (err, executionDescription) { | ||
if (err) { | ||
callback(err) | ||
} else { | ||
if (executionDescription && executionDescription.status === Status.RUNNING) { | ||
const stateMachine = stateMachines.findStateMachineByName(executionDescription.stateMachineName) | ||
const stateToRun = stateMachine.states[executionDescription.currentStateName] | ||
stateToRun.runTaskHeartbeat(executionDescription, options, callback) | ||
} else { | ||
callback( | ||
new Error(`Heartbeat has been rejected because execution is not running (executionName='${executionName}')`) | ||
) | ||
} | ||
} | ||
} | ||
) | ||
async sendTaskHeartbeat (executionName, options) { | ||
const executionDescription = await this.options.dao.findExecutionByName(executionName) | ||
if (executionDescription && executionDescription.status === Status.RUNNING) { | ||
const stateMachine = stateMachines.findStateMachineByName(executionDescription.stateMachineName) | ||
const stateToRun = stateMachine.states[executionDescription.currentStateName] | ||
return stateToRun.runTaskHeartbeat(executionDescription, options) | ||
} else { | ||
throw new Error(`Heartbeat has been rejected because execution is not running (executionName='${executionName}')`) | ||
} | ||
} // _sendTaskHeartbeat | ||
@@ -225,0 +216,0 @@ |
@@ -101,3 +101,3 @@ 'use strict' | ||
runTaskHeartbeat (executionDescription, output, callback) { | ||
async runTaskHeartbeat (executionDescription, output) { | ||
const executionName = executionDescription.executionName | ||
@@ -107,36 +107,24 @@ const tracker = this.parallelBranchTracker | ||
executionDescription.ctx = _.defaults(output, executionDescription.ctx) | ||
this.dao.setNextState( | ||
await this.dao.setNextState( | ||
executionName, // executionName | ||
executionDescription.currentStateName, // nextStateName | ||
executionDescription.currentResource, // nextResource | ||
executionDescription.ctx, // ctx | ||
function (err) { | ||
if (err) { | ||
callback(err) | ||
} else { | ||
callback(null, executionDescription) | ||
} | ||
} | ||
executionDescription.ctx | ||
) | ||
} | ||
processTaskHeartbeat (output, executionName, callback) { | ||
const _this = this | ||
this.dao.findExecutionByName( | ||
executionName, | ||
function (err, executionDescription) { | ||
if (err) { | ||
// TODO: Handle this as per spec! | ||
throw (err) | ||
} else { | ||
_this.runTaskHeartbeat( | ||
executionDescription, | ||
output, | ||
callback | ||
) | ||
} | ||
} | ||
return executionDescription | ||
} // runTaskHeartbear | ||
async processTaskHeartbeat (output, executionName) { | ||
const executionDescription = await this.dao.findExecutionByName( | ||
executionName | ||
) | ||
} | ||
return this.runTaskHeartbeat( | ||
executionDescription, | ||
output | ||
) | ||
} // processTaskHeartbeat | ||
runTaskSuccess (executionDescription, output) { | ||
@@ -143,0 +131,0 @@ const executionName = executionDescription.executionName |
@@ -31,9 +31,5 @@ 'use strict' | ||
sendTaskHeartbeat (output, callback) { | ||
sendTaskHeartbeat (output) { | ||
debug(`sendTaskHeartbeat(${this.executionName})`) | ||
if (!callback) { | ||
console.log(new Error('Missing callback parameter in call to sendTaskHeartbeat')) | ||
callback = () => {} | ||
} | ||
this.task.processTaskHeartbeat(output, this.executionName, callback) | ||
return this.task.processTaskHeartbeat(output, this.executionName) | ||
} | ||
@@ -40,0 +36,0 @@ |
{ | ||
"name": "@wmfs/statebox", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Orchestrate Node functions using Amazon States Language", | ||
@@ -5,0 +5,0 @@ "author": "West Midlands Fire Service", |
@@ -67,4 +67,4 @@ /* eslint-env mocha */ | ||
it('send in a heartbeat update (i.e. some part-filled form data)', function (done) { | ||
statebox.sendTaskHeartbeat( | ||
it('send in a heartbeat update (i.e. some part-filled form data)', async () => { | ||
const execDesc = await statebox.sendTaskHeartbeat( | ||
executionName, | ||
@@ -74,8 +74,6 @@ { | ||
}, // output | ||
{}, // executionOptions | ||
function (err, executionDescription) { | ||
expect(err).to.eql(null) | ||
done() | ||
} | ||
{} | ||
) | ||
expect(execDesc.status).to.eql('RUNNING') | ||
}) | ||
@@ -190,12 +188,8 @@ | ||
it('stopExecution (i.e. simulates a user clicking cancel on this execution)', function (done) { | ||
statebox.stopExecution( | ||
it('stopExecution (i.e. simulates a user clicking cancel on this execution)', async () => { | ||
await statebox.stopExecution( | ||
'Form flow cancelled by user', | ||
'CANCELLED', | ||
executionName, | ||
{}, | ||
function (err) { | ||
expect(err).to.eql(null) | ||
done() | ||
} | ||
{} | ||
) | ||
@@ -238,3 +232,3 @@ }) | ||
it('sendTaskHeartbeat on a stopped state machine', function (done) { | ||
it('sendTaskHeartbeat on a stopped state machine', (done) => { | ||
statebox.sendTaskHeartbeat( | ||
@@ -247,8 +241,6 @@ executionName, | ||
}, // output | ||
{}, // executionOptions | ||
function (err) { | ||
expect(err).to.be.an('error') | ||
done() | ||
} | ||
{} // executionOptions | ||
) | ||
.then(() => done(new Error('expected an error'))) | ||
.catch(() => done()) | ||
}) | ||
@@ -255,0 +247,0 @@ }) |
@@ -8,17 +8,12 @@ 'use strict' | ||
run (event, context, done) { | ||
async run (event, context, done) { | ||
console.log('WAITING FOR SOMEONE TO FILL-IN A FORM!') | ||
context.sendTaskHeartbeat( | ||
const executionDescription = await context.sendTaskHeartbeat( | ||
{ | ||
formId: 'fillThisFormInHuman!' | ||
}, | ||
function (err, executionDescription) { | ||
if (err) { | ||
throw new Error(err) | ||
} else { | ||
done(executionDescription) | ||
} | ||
} | ||
) | ||
done(executionDescription) | ||
} | ||
} |
@@ -52,3 +52,2 @@ /* eslint-env mocha */ | ||
expect(executionDescription.status).to.eql('RUNNING') | ||
executionName = executionDescription.executionName | ||
@@ -55,0 +54,0 @@ }) |
100346
2794