Auto Workflow Concept

by andypotanin

JavaScript

// Available Actions
Application( 'billing.v1' ).Action( 'process.payment', function( req, next ) { ... } );
Application( 'updates.v2' ).Action( 'sms', function( req, next ) { ... });
Application( 'users.v1' ).Action( 'validate', function( req, next ) { ... });

// A workflow is a combination of Actions organized in various ways with more advanced routing rules that available in standard Node.js Server middleware. A workflow is used to handle a business process from start to finish. A workflow may be long term.
Veneer.Workflow( "ProcessSale", {
    
    // Requst and Response Schemas for Validation - same as API Route
    "schemas": {
      "request": { ... },
      "response": { ... }
    }
    
    // Tasks use same logic as async.auto to handle dependancies.
    // Async.auto tasks will stop the process as soon as one of the steps returns an error.
    // We would need to allow for more complex rules since some steps may not be cruicial to completion
    "tasks": {
      'is_valid':                 [                   "system.parameter.validation" ],
      'authorization':            [ 'is_valid',       "billing.v1.process.payment" ],
      'sale_id':                  [ 'authorization',  "updates.v2.commit.to.database" ],
      'payment_confirmation':     [ 'authorization',  "updates.v1.send.email.notification" ],
      'shipped':                  [ 'sale_id',        "updates.v1.send.email.notification" ],
      'shipment_confirmation':    [ 'shipped',        "updates.v1.send.email.notification" ],        
    },

     // Error Handling Rules that may add additional tasks or start a child workflow process
    "error_resolution": [ "SOME LOGIC TO DETERMINE ALTERNATIVE WORKFLOW BASED ON ERROR" ],

    // States are determined based Workflow progress.
    "state": {},
    
});

// Workflow Called at soeme point
Veneer
    .Workflow( "ProcessSale" )
    .route( "REQUEST SPECIFIC DATA" )
    .on( 'success', ... ),
    .on( 'failure', ... );