# -*-coding:utf-8 -*-
# 组件启动脚本，调用组件管理提供的批量启用接口启用 jobs/jobmeta.json里描述的组件任务，以及组件自定义的动作
import json
import os

from appManager.module.global_api import ComponentHelper

DIR_PATH = os.path.split(os.path.realpath(__file__))[0]
BASE_PATH = os.path.split(DIR_PATH)[0]


def start():
    with open(os.path.join(BASE_PATH, "package.json"), "r+") as f:
        pkgConfig = json.load(f)
    app_name = pkgConfig["name"]
    componentHelper = ComponentHelper(app_name)
    # 调用组件管理接口启动任务
    componentHelper.start_task()
    # 创建kafka topic
    # createTopic()
    # 创建数据源
    # createDataSource()
    return True


if __name__ == '__main__':
    # exit 为 0，组件启动成功，为1，组件启动失败
    if start():
        exit(0)
    else:
        exit(1)
