cloudb2 / processus

A simple lightweight nodejs workflow engine designed to help orchestrate multiple tasks.
http://cloudb2.github.io/processus
Mozilla Public License 2.0
63 stars 8 forks source link

Can you please add an example with an API. I'm facing an error in example you provided. #14

Closed sgvadodariya closed 6 years ago

sgvadodariya commented 7 years ago

var processus = require('processus');

var wf = { "name": "Example Workflow", "description": "An example workflow using the API.", "tasks":{ "task 1": { "description": "Demo task to execute echo command.", "blocking": true, "handler" : "../taskhandlers/execHandler", "parameters": { "cmd": "echo 'Congratulations you called a workflow using the API.'" } } } };

processus.execute(wf, function(err, workflow){ if(!err) { console.log(workflow.tasks['task 1'].parameters.stdout); } else { console.log(err); } });

I'm getting below error.

D:\wamp64\www\Demos\processus>node test.js TypeError: Cannot read property 'dataDirectory' of undefined at Object.saveInstance (D:\wamp64\www\Demos\processus\node_modules\processus\engine\persistence\file.js:273:24) at Object.saveInstance (D:\wamp64\www\Demos\processus\node_modules\processus\engine\persistence\store.js:118:35) at realExecute (D:\wamp64\www\Demos\processus\node_modules\processus\engine\processus.js:317:9) at D:\wamp64\www\Demos\processus\node_modules\processus\engine\processus.js:143:11 at executePrePost (D:\wamp64\www\Demos\processus\node_modules\processus\engine\processus.js:193:5) at doPre (D:\wamp64\www\Demos\processus\node_modules\processus\engine\processus.js:172:3) at Object.execute (D:\wamp64\www\Demos\processus\node_modules\processus\engine\processus.js:141:5) at Object.execute (D:\wamp64\www\Demos\processus\node_modules\processus\engine\api.js:67:5) at Object. (D:\wamp64\www\Demos\processus\test.js:18:11) at Module._compile (module.js:571:32)

jasoncb2 commented 7 years ago

Hi @sgvadodariya apologies for the delayed response. You need to initialise the store which should probably be done processus.js itself. Anyway, here's a work around

var processus = require('processus');
var store = require('processus/engine/persistence/store');
store.initStore(function(err){
  console.log(err);
});

var wf = {
  "name": "Example Workflow",
  "description": "An example workflow using the API.",
  "tasks":{
    "task 1": {
      "description": "Demo task to execute echo command.",
      "blocking": true,
      "handler" : "../taskhandlers/execHandler",
      "parameters": {
        "cmd": "echo 'Congratulations you called a workflow using the API.'"
      }
    }
  }
};

processus.execute(wf, function(err, workflow){
  if(!err) {
    console.log(workflow.tasks['task 1'].parameters.stdout);
  }
  else {
    console.log(err);
  }
});

which should result in the following:

info: ⧖ Starting task [task 1]
info: Congratulations you called a workflow using the API.
info: ✔ task task 1 completed successfully.
Congratulations you called a workflow using the API.
jasoncb2 commented 7 years ago

For more info on the store and parameters, look at how the cli.js code uses processes to do the same.

jasoncb2 commented 6 years ago

Updated readme to include store initialization in API example. Closing this accordingly.