Skip to content

Commit

Permalink
feat(valhalla): allow to configure exec timeout (#111)
Browse files Browse the repository at this point in the history
* feat(valhalla): allow to configure exec timeout

* doc: add exec_tiemout description

* doc: update changelog
  • Loading branch information
tetram authored Dec 18, 2024
1 parent a834d55 commit fe06e85
Show file tree
Hide file tree
Showing 3 changed files with 12 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.8
ADDED:
- Valhalla: allow to configure a timeout on valhalla_service exec

## 2.2.7
ADDED:
- Valhalla: Provide the ability to set maxBuffer in exec command options to avoid maxBuffer lenght exceeded error (#109)
Expand Down
4 changes: 4 additions & 0 deletions documentation/production/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ Road2 peut être directement interrogé en HTTPS. Pour cela, il utilise le modul

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.

### Gestion du timeout valhalla
Il est possible de changer la valeur du timeout d'execution du process valhalla_service en valorisant la variable d'environnement `EXEC_TIMEOUT` (nombre de millisecondes).
La valeur par défaut est `0` soit pas de timeout.
6 changes: 4 additions & 2 deletions src/js/sources/valhallaSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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;
// Récupération de la valeur du timeout pour l'execution du valhalla_service en variable d'environnement ou valorisation par défaut (0)
const execTimeout = process.env.EXEC_TIMEOUT ? parseInt(process.env.EXEC_TIMEOUT, 10) : 0;

/**
*
Expand Down Expand Up @@ -188,7 +190,7 @@ 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 };
const options = { maxBuffer: maxBuffer, timeout: execTimeout };
LOGGER.info(commandString);

return new Promise( (resolve, reject) => {
Expand Down Expand Up @@ -290,7 +292,7 @@ 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 };
const options = { maxBuffer: maxBuffer, timeout: execTimeout };
LOGGER.info(commandString);

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

0 comments on commit fe06e85

Please sign in to comment.