Stages

In a step, the index.js file implements the flow. The scaffold generates a file like this:

'use strict';

module.exports = {
  check: function() {
    this.logger.info('#blue', 'Check if all you need to execute this step exists');
  },

  config: function() {
    this.logger.info('#yellow', 'Config the step to run');
  },

  run: function(ok, ko) {
    this.sh('echo Run main execution of the step', ko, true);
  },

  prove: function() {
    this.logger.info('#green', 'Check if the step has run ok');
  },

  notify: function() {
    this.logger.info('#grey', 'Notify the end of the shot to someone or something');
  },

  emit: function() {
    this.logger.info('#white', 'Emit the result of the step to other steps. Allow communication between steps');
    return { message: 'emit a message' };
  }
};

And the stages of a step by default are:

  1. check: check if all you need to execute this step exists.
  2. config: config the step to run.
  3. run: run main execution of the step.
  4. prove: check if the step has run ok.
  5. notify: notify the end of the step to someone or something.
  6. emit: emit the result of the step to other steps. Allow communication between steps.

Promises

Note that all the stages are promises functions, they has two optional paramenter 'resolve', 'reject';

A example with resolve and reject:

module.exports = {
  run: function(resolve, reject) {
    if (this.params.jsonIsWellFormed) {
      resolve();
    } else {
      reject();
    }
    return;
  }
};

check stage

Check if all you need to execute this step exists. Here you can see some examples:

config stage

Config the step to run. Do you need to config something, this is the stage to do it.

run stage

Run main execution of the step. This stage hope that all that it need to implement a process is 'ok', because it has been provide by the above stage.

prove stage

Check if the step has run ok.

notify stage

Notify the end of the shot to someone or something.

emit stage

Emit the result of the step to other steps. Allow communication between steps.

See parameters between steps for more information.

Note: Stages are configured on piscosour.json file of every recipe, it is possible to overwrite stages parameters on piscosour.json, see recipe configuration for more information.