parent
5bb28d2ebb
commit
a2de66574f
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/9 14:53
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : __init__.py.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc :
|
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/12 15:09
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : fu_function.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc :
|
||||||
|
def singleton(cls):
|
||||||
|
"""
|
||||||
|
单例装饰器
|
||||||
|
:param cls:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
_instance = {}
|
||||||
|
|
||||||
|
def inner():
|
||||||
|
if cls not in _instance:
|
||||||
|
_instance[cls] = cls()
|
||||||
|
return _instance[cls]
|
||||||
|
|
||||||
|
return inner
|
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/9 15:37
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : local_db_conf.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc : 数据库连接配置
|
||||||
|
from datahub.datasource.constant import ds_conf_param
|
||||||
|
from common.fudb.connectors.connector_factory import ConnFactory
|
||||||
|
|
||||||
|
# 系统使用数据库配置 数据库类型 用户名 密码 host 端口 默认数据库
|
||||||
|
local_db = ds_conf_param('postgresql', 'postgres', 'root@123', 'localhost', 5432, 'postgres')
|
||||||
|
local_conn = ConnFactory(local_db)
|
@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/9 14:41
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : metadata_warehouse.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc : 元数据存储
|
||||||
|
|
||||||
|
from common.futool.fu_id import id_gen
|
||||||
|
|
||||||
|
|
||||||
|
class MetadataWareHouse(object):
|
||||||
|
"""
|
||||||
|
元数据仓库
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, source_id):
|
||||||
|
self.source_id = source_id
|
||||||
|
|
||||||
|
def save_metadata_obj(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def save_metadata_obj_detail(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def save_metadata_obj_field(self):
|
||||||
|
pass
|
@ -1,7 +1,14 @@
|
|||||||
[oracle]
|
[oracle]
|
||||||
tables = select distinct table_name from user_tab_comments where table_type='TABLE'
|
tables = select distinct table_name from user_tab_comments where table_type='TABLE'
|
||||||
views = select distinct table_name from user_tab_comments where table_type='VIEW'
|
views = select distinct table_name from user_tab_comments where table_type='VIEW'
|
||||||
|
procedure = select distinct name From user_source where type = 'PROCEDURE'
|
||||||
|
view_detail = select text from all_views where view_name='#$#'
|
||||||
|
procedure_detail = SELECT text FROM user_source WHERE NAME = '#$#' ORDER BY line
|
||||||
|
table_field = select b.COLUMN_NAME,a.COMMENTS, b.COLUMN_ID, b.DATA_TYPE, b.DATA_LENGTH, b.NULLABLE, b.DEFAULT_LENGTH, b.DATA_DEFAULT from user_col_comments a left join user_tab_columns b on a.table_name=b.table_name
|
||||||
|
and a.COLUMN_NAME = b.COLUMN_NAME where a.table_name = '#$#' ORDER BY b.COLUMN_ID asc
|
||||||
|
|
||||||
[postgresql]
|
[postgresql]
|
||||||
tables = SELECT distinct table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name
|
tables = SELECT distinct table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name
|
||||||
views = select distinct table_name from information_schema.views WHERE table_schema = 'public' ORDER BY table_name
|
views = select distinct table_name from information_schema.views WHERE table_schema = 'public' ORDER BY table_name
|
||||||
|
view_detail =
|
||||||
|
procedure_detail =
|
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/11 18:52
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : __init__.py.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc : 任务定时调度模块
|
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/11 19:08
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : scan_task.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc : 扫描任务,通过调度扫描数据源-->获取数据源-->读取元数据并同步
|
||||||
|
from datahub.local_db_conf import local_conn
|
||||||
|
from datahub.scheduletask.scandao.scan_task_dao import ScanTaskDao
|
||||||
|
|
||||||
|
|
||||||
|
class ScanTaskManage(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.dao = ScanTaskDao(local_conn)
|
||||||
|
|
||||||
|
def add_task(self, source_id, cron='0 0 0 1/1 * ?'):
|
||||||
|
"""
|
||||||
|
添加任务
|
||||||
|
:param source_id: 数据源ID
|
||||||
|
:param cron: cron表达式
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
if self.dao.exist_by_id(source_id):
|
||||||
|
return False, f'[{source_id}] all ready exist'
|
||||||
|
return self.dao.add_task(source_id, cron), 'add success'
|
||||||
|
|
||||||
|
def switch_task(self, source_id, enable='N'):
|
||||||
|
"""
|
||||||
|
开关任务
|
||||||
|
:param source_id: 源ID
|
||||||
|
:param enable: 是否开启 Y开|N关
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self.dao.switch_task(source_id, enable)
|
||||||
|
|
||||||
|
def edit_cron(self, source_id, cron):
|
||||||
|
"""
|
||||||
|
修改任务CRON表达式
|
||||||
|
:param source_id: 源ID
|
||||||
|
:param cron: cron表达式
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self.dao.edit_task_cron(source_id, cron)
|
||||||
|
|
||||||
|
def query_task(self, enable=None):
|
||||||
|
"""
|
||||||
|
任务查询
|
||||||
|
:param enable:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self.dao.query_all_task(enable)
|
||||||
|
|
||||||
|
def query_task_by_id(self, source_id):
|
||||||
|
"""
|
||||||
|
根据ID 查任务
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self.dao.query_task_by_id(source_id)
|
||||||
|
|
||||||
|
|
||||||
|
scan_task_manage = ScanTaskManage()
|
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/12 15:24
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : __init__.py.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc :
|
@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/12 15:24
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : scan_task_dao.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc :
|
||||||
|
|
||||||
|
from common.fudb.connectors.connector_factory import ConnFactory
|
||||||
|
from common.fudb.dbapis.fu_dao import BaseDao
|
||||||
|
|
||||||
|
|
||||||
|
class ScanTaskDao(BaseDao):
|
||||||
|
def __init__(self, connector: ConnFactory):
|
||||||
|
super().__init__(connector)
|
||||||
|
|
||||||
|
def add_task(self, source_id, cron):
|
||||||
|
return self.execute_update(
|
||||||
|
f"insert into scan_task_conf (source_id,cron_expression) values ('{source_id}','{cron}')") > 0
|
||||||
|
|
||||||
|
def exist_by_id(self, source_id):
|
||||||
|
"""
|
||||||
|
判断任务是否存在
|
||||||
|
:param source_id:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self.query_one(f"select count(1) from scan_task_conf where source_id='{source_id}'")[0] > 0
|
||||||
|
|
||||||
|
def remove_task(self, source_id):
|
||||||
|
return self.execute_update(f"delete from scan_task_conf where source_id='{source_id}'") > 0
|
||||||
|
|
||||||
|
def switch_task(self, source_id, enable):
|
||||||
|
"""
|
||||||
|
开关任务
|
||||||
|
:param source_id: 数据源ID
|
||||||
|
:param enable: Y开启 N关闭
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self.execute_update(f"update scan_task_conf set enable='{enable}' where source_id='{source_id}'") > 0
|
||||||
|
|
||||||
|
def edit_task_cron(self, source_id, cron):
|
||||||
|
"""
|
||||||
|
修改任务cron表达式
|
||||||
|
:param source_id: 数据源ID
|
||||||
|
:param cron: cron表达式
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self.execute_update(
|
||||||
|
f"update scan_task_conf set cron_expression='{cron}' where source_id='{source_id}'") > 0
|
||||||
|
|
||||||
|
def query_all_task(self, enable):
|
||||||
|
"""
|
||||||
|
查询所有已开启任务
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
if not enable:
|
||||||
|
return self.query_all("select source_id,cron_expression from scan_task_conf")
|
||||||
|
return self.query_all(f"select source_id,cron_expression from scan_task_conf where enable='{enable}'")
|
||||||
|
|
||||||
|
def query_task_by_id(self, source_id):
|
||||||
|
"""
|
||||||
|
源ID 查任务
|
||||||
|
:param source_id:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self.query_one(
|
||||||
|
f"select source_id,cron_expression,enable from scan_task_conf where source_id='{source_id}'")
|
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Time : 2023/4/11 19:10
|
||||||
|
# @Author : old tom
|
||||||
|
# @File : task_executor.py
|
||||||
|
# @Project : futool-tiny-datahub
|
||||||
|
# @Desc : 任务执行器,负责将任务添加到scheduler队列中
|
||||||
|
from common.futool.fu_function import singleton
|
||||||
|
|
||||||
|
|
||||||
|
@singleton
|
||||||
|
class CommonTaskExecutor(object):
|
||||||
|
"""
|
||||||
|
通用任务执行器
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, scheduler, cron_trigger):
|
||||||
|
"""
|
||||||
|
:param scheduler: 调度器
|
||||||
|
:param cron_trigger: cron触发器
|
||||||
|
"""
|
||||||
|
self.cron_trigger = cron_trigger
|
||||||
|
self.scheduler = scheduler
|
||||||
|
|
||||||
|
def submit(self, source_id, cron):
|
||||||
|
"""
|
||||||
|
提交任务
|
||||||
|
:param source_id: 数据源ID
|
||||||
|
:param cron: cron表达式
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
pass
|
@ -1,3 +0,0 @@
|
|||||||
20230408 11:11:37 - MainProcess | MainThread | test_log.test:16 - INFO -fefefe
|
|
||||||
20230408 11:11:37 - MainProcess | MainThread | test_log.test:17 - ERROR -223232
|
|
||||||
20230408 11:11:37 - MainProcess | MainThread | test_log.test:18 - WARNING -999
|
|
Loading…
Reference in new issue