Skip to content

Commit

Permalink
Merge branch '298-spawn-process' into 'dev'
Browse files Browse the repository at this point in the history
spawn process

Closes #298

See merge request ergo/rosen-bridge/guard-service!241
  • Loading branch information
vorujack committed Sep 16, 2023
2 parents 02ceece + 8e9b8e0 commit 16d00cb
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/guard/Tss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import CommunicationConfig from '../communication/CommunicationConfig';
import Dialer from '../communication/Dialer';
import { loggerFactory } from '../log/Logger';
import Configs from '../configs/Configs';
import * as childProcess from 'child_process';
import { spawn } from 'child_process';

const logger = loggerFactory(import.meta.url);
const exec = childProcess.exec;

class Tss {
private static instance: Tss;
Expand All @@ -39,26 +38,32 @@ class Tss {
* runs tss binary file
*/
protected static runBinary = (): void => {
const tssPath =
Configs.tssExecutionPath +
' -configFile ' +
Configs.tssConfigPath +
` -guardUrl http://${Configs.apiHost}:${Configs.apiPort}` +
` -host ${Configs.tssUrl}:${Configs.tssPort}`;
exec(tssPath, function (err, data) {
if (err !== null) {
const args = [
'-configFile',
Configs.tssConfigPath,
'-guardUrl',
`http://${Configs.apiHost}:${Configs.apiPort}`,
'-host',
`${Configs.tssUrl}:${Configs.tssPort}`,
];
spawn(Configs.tssExecutionPath, args, {
detached: false,
})
.addListener('close', (code) => {
const timeout = Configs.tssInstanceRestartGap;
logger.error(
`TSS binary failed unexpectedly, TSS will be started in [${timeout}] seconds`
);
logger.debug(`Tss failure error: ${err}`);
logger.debug(`Tss failure data: ${data}`);
logger.debug(`Tss failure error code: ${code}`);
// wait some seconds to start again
setTimeout(Tss.runBinary, timeout * 1000);
} else {
})
.addListener('spawn', () => {
logger.info('TSS binary started');
}
});
})
.addListener('error', (err: Error) => {
logger.error(`an error occured when trying to spawn: ${err}`);
});
};

/**
Expand Down

0 comments on commit 16d00cb

Please sign in to comment.