Commit 82314e826f0fce75a1fae8d4d122816db340def9

Authored by Adhidarma Hadiwinoto
1 parent f942a8afb4
Exists in master

Add locations on requesting task from CORE

Showing 2 changed files with 20 additions and 0 deletions Side-by-side Diff

... ... @@ -20,6 +20,7 @@ const logger = require('tektrans-logger');
20 20 const report = require('./lib/report');
21 21  
22 22 const sleep = require('./lib/sleep');
  23 +const composeGatewayLocations = require('./lib/compose-gateway-locations');
23 24  
24 25 let partner;
25 26 let first = true;
... ... @@ -56,6 +57,7 @@ async function getTask() {
56 57 const payload = {
57 58 handler: config.handler || config.handler_name,
58 59 products: config.products || [],
  60 + locations: composeGatewayLocations(config),
59 61 };
60 62  
61 63 let task;
lib/compose-gateway-locations.js
... ... @@ -0,0 +1,18 @@
  1 +/**
  2 + * @param {Object} config
  3 + * @param {Array.<string>} [config.locations]
  4 + * @returns {Array.<string>}
  5 + */
  6 +module.exports = (config) => {
  7 + const retval = ((
  8 + Array.isArray(config.locations) && config.locations.length && config.locations)
  9 + || []
  10 + )
  11 + .filter((item) => typeof item === 'string')
  12 + .map((item) => item.trim())
  13 + .filter((item) => item.length);
  14 +
  15 + if (!retval.length) retval.push('ALL');
  16 +
  17 + return retval;
  18 +};