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.

41 lines
1.1 KiB

#!/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 datahub.scheduletask.schedule import sch
class ScheduleExecutor(object):
"""
定时任务任务执行器
"""
def __init__(self, scheduler=sch):
"""
:param scheduler: 调度器默认使用BackgroundScheduler
"""
self.scheduler = scheduler
def submit(self, source_id, cron_trigger, execute_fun):
"""
提交任务
:param execute_fun: 定时任务执行函数
:param cron_trigger: cron触发器
:param source_id: 数据源ID
:return:
"""
self.scheduler.add_job(execute_fun, trigger=cron_trigger, id=source_id, kwargs={
'source_id': source_id
})
def remove_job(self, source_id):
"""
移除任务
:param source_id:
:return:
"""
self.scheduler.remove_job(job_id=source_id)