Skip to content

Commit

Permalink
Merge pull request #109 from mproboeuf/feat-exec-maxbuffer
Browse files Browse the repository at this point in the history
feat: handle exec maxBuffer size with environment variable
  • Loading branch information
azarz authored Dec 13, 2024
2 parents 8b54a88 + 905ab97 commit 3bacff8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 2.2.7
ADDED:
- Valhalla: Provide the ability to set maxBuffer in exec command options to avoid maxBuffer lenght exceeded error

## 2.2.6
FIXED:
- Ignore turf errors for steps simplification in pgrSource, and add a warning to analyse which steps trigger the error
Expand Down
5 changes: 5 additions & 0 deletions documentation/production/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ Par défaut, il y a des options qui sont utilisées mais elles peuvent être rem
### Gestion du HTTPS

Road2 peut être directement interrogé en HTTPS. Pour cela, il utilise le module `https` de NodeJS. Il est donc possible de lui fournir les [options](https://nodejs.org/docs/latest-v12.x/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) disponibles dans ce module.

### Gestion du buffer

Il est possible de changer la taille du buffer lors d'une source Valhalla en valorisant la variable d'environnement `EXEC_MAX_BUFFER_SIZE`.
La valeur par défaut est de 1MB.
8 changes: 6 additions & 2 deletions src/js/sources/valhallaSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const { exec } = require('child_process');
// Création du LOGGER
const log4js = require('log4js');
const LOGGER = log4js.getLogger("VALHALLASOURCE");
// Récupération de la valeur du maxBuffer en variable d'environment variable ou valorisation par défaut (1MB)
const maxBuffer = process.env.EXEC_MAX_BUFFER_SIZE ? parseInt(process.env.EXEC_MAX_BUFFER_SIZE, 10) : 1024 * 1024;

/**
*
Expand Down Expand Up @@ -186,12 +188,13 @@ module.exports = class valhallaSource extends Source {
// Permet de grandement se simplifier le parsing !!
const optionsString = `"directions_options":{"format":"osrm"}`;
const commandString = `valhalla_service ${this._configuration.storage.config} route '{${locationsString},${costingString},${optionsString}}' `;
const options = { maxBuffer: maxBuffer };
LOGGER.info(commandString);

return new Promise( (resolve, reject) => {

try {
exec(commandString, (err, stdout, stderr) => {
exec(commandString, options, (err, stdout, stderr) => {

// Du moment qu'OSRM a répondu, on considère que la source est joignable
this.state = "green";
Expand Down Expand Up @@ -287,12 +290,13 @@ module.exports = class valhallaSource extends Source {
const reverseString = `"reverse":${reverse}`;
const polygonsString = `"polygons":true`;
const commandString = `valhalla_service ${this._configuration.storage.config} isochrone '{${locationsString},${costingString},${costingOptionsString},${contoursString},${reverseString},${polygonsString}}' `;
const options = { maxBuffer: maxBuffer };
LOGGER.info(commandString);

return new Promise( (resolve, reject) => {

try {
exec(commandString, (err, stdout, stderr) => {
exec(commandString, options, (err, stdout, stderr) => {

// Du moment qu'OSRM a répondu, on considère que la source est joignable
this.state = "green";
Expand Down

0 comments on commit 3bacff8

Please sign in to comment.