Auto Workflow Concept
by andypotanin
JavaScript
// Available Actions
Application( 'Updates' ).Action( 'sms', function( req, next ) { ... });
Application( 'Users' ).Action( 'validate', function( req, next ) { ... });
// The inner-logic of an action is demostrated below:
Application( 'Billing' ).Action( 'process', function( req, res, next ) {
// Some sort of conditional mapping to handle Errors and attempt to automatically select another workflow that will resolve the issue
this.error_resolution([
{
// This is written in plain words to explain what should happen, I don't knwo of a good way to do this via JSON/JS
'when Error X occurs within this Action, execute the following Workflow': [
'some.method.that.fixes.issue',
'another method that verifies it',
'return back to this action to complete the process',
]
}
]);
this.auto({
'is_valid': function( req, next ) {
// Validation of request parameters
next( null, true );
},
'authorization': [ 'valid', function( req, next ) {
// API request to merchant process, returning response
next( null, { 'valid': true, 'id': 3234324 } );
}],
'sale_id': [ 'authorization', function( req, next ) {
// Add sale entry to database, returning ID
next( null, id );
}]
}, function( error, report ) {
// No errors leave this action
if( !error ) {
next( null, report );
}
// Have error but a resolution entry exists. Resolution workflow is started.
if( error && this.resolvable ) {
this.resolve( error ).on( "resolved", next );
});
// Error occured and no resolution workflows are available
if( error && !this.resolvable ) {
next( error );
...