You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.2 KiB

#!/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}'")