forked from cerc-io/laconic-console
fix: load bf topic. (#60)
This commit is contained in:
parent
2dd3022fa4
commit
3ae327a2d1
@ -15,18 +15,19 @@ const SERVICE_CONFIG_FILENAME = 'service.yml';
|
|||||||
|
|
||||||
const log = debug('dxos:console:server:resolvers');
|
const log = debug('dxos:console:server:resolvers');
|
||||||
|
|
||||||
|
let topic;
|
||||||
const getBotFactoryTopic = (botFactoryCwd) => {
|
const getBotFactoryTopic = (botFactoryCwd) => {
|
||||||
// TODO(egorgripasov): Get topic from config or registry.
|
if (!topic) {
|
||||||
const serviceFilePath = path.join(os.homedir(), botFactoryCwd || DEFAULT_BOT_FACTORY_CWD, SERVICE_CONFIG_FILENAME);
|
// TODO(egorgripasov): Get topic from config or registry.
|
||||||
if (fs.existsSync(serviceFilePath)) {
|
const serviceFilePath = path.join(os.homedir(), botFactoryCwd || DEFAULT_BOT_FACTORY_CWD, SERVICE_CONFIG_FILENAME);
|
||||||
const { topic } = yaml.safeLoad(fs.readFileSync(serviceFilePath));
|
if (fs.existsSync(serviceFilePath)) {
|
||||||
return topic;
|
const botFactoryInfo = yaml.safeLoad(fs.readFileSync(serviceFilePath));
|
||||||
|
topic = botFactoryInfo.topic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return topic;
|
||||||
};
|
};
|
||||||
|
|
||||||
const topic = getBotFactoryTopic();
|
|
||||||
|
|
||||||
const executeCommand = async (command, args, timeout = 10000) => {
|
const executeCommand = async (command, args, timeout = 10000) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const child = spawn(command, args, { encoding: 'utf8' });
|
const child = spawn(command, args, { encoding: 'utf8' });
|
||||||
@ -59,7 +60,7 @@ const executeCommand = async (command, args, timeout = 10000) => {
|
|||||||
|
|
||||||
const getRunningBots = async () => {
|
const getRunningBots = async () => {
|
||||||
const command = 'wire';
|
const command = 'wire';
|
||||||
const args = ['bot', 'factory', 'status', '--topic', topic];
|
const args = ['bot', 'factory', 'status', '--topic', getBotFactoryTopic()];
|
||||||
|
|
||||||
const { code, stdout, stderr } = await executeCommand(command, args);
|
const { code, stdout, stderr } = await executeCommand(command, args);
|
||||||
return {
|
return {
|
||||||
@ -71,7 +72,7 @@ const getRunningBots = async () => {
|
|||||||
|
|
||||||
const sendBotCommand = async (botId, botCommand) => {
|
const sendBotCommand = async (botId, botCommand) => {
|
||||||
const command = 'wire';
|
const command = 'wire';
|
||||||
const args = ['bot', botCommand, '--topic', topic, '--bot-id', botId];
|
const args = ['bot', botCommand, '--topic', getBotFactoryTopic(), '--bot-id', botId];
|
||||||
|
|
||||||
const { code, stdout, stderr } = await executeCommand(command, args);
|
const { code, stdout, stderr } = await executeCommand(command, args);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user