Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
079438c
后端:添加rpyc+apscheduler服务
4linuxfun Feb 24, 2023
30c6b8e
后端:rpyc+apscheduler服务 fix #100
4linuxfun Feb 24, 2023
46d69e6
后端: 添加任务管理对应接口 fix #100
4linuxfun Feb 24, 2023
9532018
前端:任务中心-任务管理:功能实现 fix #100
4linuxfun Feb 24, 2023
d4e6530
前端:组件封装
4linuxfun Feb 24, 2023
6057efe
后端:通过rpyc实现apscheduler的远程调用,进行任务的管理
4linuxfun Jun 19, 2023
065e8f0
后端:添加Job相关model和crud
4linuxfun Jun 19, 2023
d86d098
后端:添加get_uid依赖
4linuxfun Jun 20, 2023
b9c9caf
后端:修改使用get_uid获取uid
4linuxfun Jun 20, 2023
ce6ee7c
后端:增加get_redis函数,用户获取redis连接
4linuxfun Jun 20, 2023
39ca9f2
后端:实现ws获取redis中的日志信息
4linuxfun Jun 20, 2023
b0b99bf
后端:修改job项目目录
4linuxfun Jun 20, 2023
c297407
后端:添加任务管理相关借口
4linuxfun Jun 20, 2023
9980ee6
前端:实现任务管理相关功能页面
4linuxfun Jun 20, 2023
95d60e5
后端:scheduler后端task进行执行主机任务分离,方便后期扩展执行远程ssh
4linuxfun Jun 28, 2023
80a277f
后端:job增加targets参数,用于指定任务执行主机
4linuxfun Jun 28, 2023
0a438e2
前端:修复升级element plus后中文乱码问题
4linuxfun Jun 28, 2023
cb45acf
前端:任务管理增加targets参数
4linuxfun Jun 28, 2023
f0e7cc5
后端:scheduer增加get_user_jobs,通过uid和job_name快速获取用户的job列表
4linuxfun Jun 30, 2023
2486db8
后端:scheduler task增加时间值
4linuxfun Jun 30, 2023
7e9e4bf
后端:优化任务获取逻辑
4linuxfun Jun 30, 2023
6cee979
后端:重新定义Job相关模型
4linuxfun Jun 30, 2023
0bb4ba9
前端:优化任务管理页面相关代码
4linuxfun Jun 30, 2023
1ce9cc8
前端:任务日志页面展示
4linuxfun Jun 30, 2023
7fd5c91
更新前后端项目依赖版本
4linuxfun Dec 21, 2023
3dc9ea1
update:更新依赖库版本
4linuxfun Jan 3, 2024
58d095b
后端:修复更新pydantic后属性变更
4linuxfun Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
后端:scheduler后端task进行执行主机任务分离,方便后期扩展执行远程ssh
  • Loading branch information
4linuxfun committed Jun 28, 2023
commit 95d60e570132bd5101f08feed5c89be6a6468389
52 changes: 36 additions & 16 deletions rpyc_scheduler/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import json
from typing import List, Dict, Any
from datetime import datetime
from loguru import logger
from sqlmodel import text
Expand All @@ -8,28 +9,47 @@
from models import engine


def run_command_with_channel(job_id=None, command=None):
"""
本地执行命令,并把任务实时输入redis中。任务结束后,日志写入数据库中
:param job_id:任务名
:param command: 执行的命令
"""
with Channel(rpc_config.redis, job_id=job_id) as channel:
logger.debug(f"job id:{job_id}")
def local_executor(job_id, host, command):
with Channel(rpc_config.redis, job_id=f"{job_id}:{host}") as channel:
start_time = datetime.now()
channel.send({'msg': '开始执行任务:'})
channel.send({'msg': f"执行命令:{command}"})
start_time = datetime.now()
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,
shell=True)
while (status := process.poll()) is None:
message = process.stdout.readline()
channel.send({'msg': message})
channel.send({'msg': '结束执行任务'})
end_time = datetime.now()
with engine.connect() as conn:
sql = text(
"INSERT INTO job_log (status,job_id,start_time,end_time,log) values (:status,:job_id,:start_time,:end_time,:log)")
conn.execute(sql,
{'status': status, 'job_id': job_id, 'start_time': start_time, 'end_time': end_time,
'log': json.dumps(channel.msg)})
conn.commit()
return status, end_time - start_time, channel.msg


def host_executor(job_id, host, command):
pass


def run_command_with_channel(job_id=None, targets: List[str] = None, command=None):
"""
本地执行命令,并把任务实时输入redis中。任务结束后,日志写入数据库中
:param job_id:任务名
:param targets: 主机列表
:param command: 执行的命令
"""
run_logs: Dict[str, Dict[str, Any]] = {}
remote_host: List[str] = []
for host in targets:
if host == 'localhost':
status, duration, log = local_executor(job_id, host, command)
run_logs[host] = {'status': status,
'duration': 0,
'log': log}
else:
remote_host.append(host)

with engine.connect() as conn:
sql = text(
"INSERT INTO job_log (status,job_id,log) values (:status,:job_id,:log)")
conn.execute(sql,
{'status': status, 'job_id': job_id,
'log': json.dumps(run_logs)})
conn.commit()