Task Development

Learn how to code DEX8 Tasks

Main File

File "main.js" is the main execution file.
This is the starting point where the process is initialised. It includes all other Javascript files which are JS functions.

Injected DEX8-SDK Helper Libraries

The DEX8 Robot automatically injects libraries into the main file via "lib" argument. Those libraries are:

  • FunctionFlow - controls functions
  • Echo - sends realtime messages to the Web Panel or terminal
  • Mongo - manages mongoDB database & collection
  • HttpClient - HTTP Client (can be used instead of Puppeteer)
  • Rand - stohastic number and shuffle array generator

FunctionFlow ®

By using DEX8-SDK FunctionFlow helper library the functions can be organized and executed in serial or parallel flow. Also, it gives the option to repeat a group of serially executed functions.

For example:

const f1 = require('./f1.js'); // 1st function
const f2 = require('./f2.js'); // 2nd function
const f3 = require('./f3.js'); // 3rd function

module.exports = async (input, lib) => {
  const ff = lib.ff; // dex8-sdk FunctionFlow instance
  const echo = lib.echo; // dex8-sdk Echo instance
  const mongo = lib.mongo; // dex8-sdk Mongo instance
  const httpClient = new lib.HttpClient(); // dex8-sdk HttpClient instance
  const rand = new lib.Rand(); // dex8-sdk Rand instance


  const x = {
    ...input,
    somethingCustom: 22
  }

  ff.setOpts({debug: false, msDelay: 700}); // set options
  ff.xInject(x); // inject input into the functions - then you can use module.exports = func(x, lib) { ... }
  ff.libInject(lib); // injects library into the functions  - then you can use module.exports = func(x, lib) { ... }

  echo.log('x.somethingCustom::', x.somethingCustom);

  await ff.serial([f1, f2, f3]); // executes f1, f2 and f3 one after another
  const y = await ff.repeat(3); // repeats ff.serial() 3 times, e.g repeats group of serially executed functions 3 times

  echo.log('output::', y.a);

  return y; // or return ff.x;
};
          

The complete example is available here.

Notice that FunctionFlow and Echo helper objects are instantiated and injected by the DEX8 Robot. It can be used simply by lib.echo and lib.ff