fix: load bf topic. (#60)

This commit is contained in:
Egor Gripasov 2020-12-16 12:13:17 +03:00 committed by GitHub
parent 2dd3022fa4
commit 3ae327a2d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,18 +15,19 @@ const SERVICE_CONFIG_FILENAME = 'service.yml';
const log = debug('dxos:console:server:resolvers');
let topic;
const getBotFactoryTopic = (botFactoryCwd) => {
// TODO(egorgripasov): Get topic from config or registry.
const serviceFilePath = path.join(os.homedir(), botFactoryCwd || DEFAULT_BOT_FACTORY_CWD, SERVICE_CONFIG_FILENAME);
if (fs.existsSync(serviceFilePath)) {
const { topic } = yaml.safeLoad(fs.readFileSync(serviceFilePath));
return topic;
if (!topic) {
// TODO(egorgripasov): Get topic from config or registry.
const serviceFilePath = path.join(os.homedir(), botFactoryCwd || DEFAULT_BOT_FACTORY_CWD, SERVICE_CONFIG_FILENAME);
if (fs.existsSync(serviceFilePath)) {
const botFactoryInfo = yaml.safeLoad(fs.readFileSync(serviceFilePath));
topic = botFactoryInfo.topic;
}
}
return undefined;
return topic;
};
const topic = getBotFactoryTopic();
const executeCommand = async (command, args, timeout = 10000) => {
return new Promise((resolve) => {
const child = spawn(command, args, { encoding: 'utf8' });
@ -59,7 +60,7 @@ const executeCommand = async (command, args, timeout = 10000) => {
const getRunningBots = async () => {
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);
return {
@ -71,7 +72,7 @@ const getRunningBots = async () => {
const sendBotCommand = async (botId, botCommand) => {
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);