Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
53ba21d
update:前端-优化useTerm实现代码
4linuxfun Jan 17, 2025
2143ded
update:后端-简化scheduler任务,删除不必要代码
4linuxfun Jan 21, 2025
8daef2b
update:后端-scheduler完善
4linuxfun Jan 21, 2025
ae16ea1
update:后端-排除websocket权限验证
4linuxfun Jan 21, 2025
19e8bad
update:后端-实现“任务管理”模块功能
4linuxfun Jan 21, 2025
f2bf6d5
update:前端-重构usePagination
4linuxfun Jan 21, 2025
bf8f03c
update:前端-实现“执行任务”功能
4linuxfun Jan 21, 2025
c3c18b5
update:前端usePagination分页增加initialPageSize参数
4linuxfun Feb 10, 2025
7647004
update:前端-任务管理分页日志默认改为5
4linuxfun Feb 10, 2025
3544264
update:service.sh脚本增加部分逻辑判断
4linuxfun Feb 10, 2025
c75e188
update:前端usePagination补全async写法
4linuxfun Feb 11, 2025
9091c98
update:前端-补全缺失组件引用
4linuxfun Feb 11, 2025
ac23b67
fix:前端-修复主机选择关联带出bug
4linuxfun Feb 11, 2025
f9f57b1
fix:前端-修复翻页多选状态保持问题
4linuxfun Feb 12, 2025
e6a1b58
update:后端-更新config配置模式
4linuxfun Feb 12, 2025
23865ae
update:后端-修改yaml配置后的参数
4linuxfun Feb 12, 2025
e9c7183
update:后端-更新服务控制脚本
4linuxfun Feb 12, 2025
e493d2c
update:后端-修改redis过期时间
4linuxfun Feb 12, 2025
28ba966
update:后端-任务管理功能模块实现
4linuxfun Feb 12, 2025
0413a51
update:更新README.md
4linuxfun Feb 13, 2025
fd9180a
update:后端-增加生产环境配置模板
4linuxfun Feb 13, 2025
9cb6b59
update:其他
4linuxfun Feb 13, 2025
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
update:后端-修改yaml配置后的参数
  • Loading branch information
4linuxfun committed Feb 12, 2025
commit 23865ae5c9b35b16b391d58273fd5f5ceab930a5
25 changes: 16 additions & 9 deletions rpyc_scheduler/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
from pydantic_settings import BaseSettings
from pydantic import MySQLDsn, RedisDsn
import yaml
import os
from pathlib import Path

# 获取环境变量,默认为 development
env = os.getenv('ENV', 'development')
config_path = Path(__file__).parent.parent / 'config' / f'{env}.yaml'

class RpcConfig(BaseSettings):
# apscheduler指定job store和excutors
apscheduler_job_store: MySQLDsn = 'mysql+pymysql://root:[email protected]/devops'
redis: dict = {'host': '192.168.137.129', 'password': 'seraphim', 'port': 6379, 'health_check_interval': 30}
rpc_port: int = 18861
# 初始化配置变量
rpc_config = {}

# 读取配置文件
def load_config():
global rpc_config
with open(config_path, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
rpc_config.update(config['scheduler'])


rpc_config = RpcConfig()
# 加载配置
load_config()
4 changes: 2 additions & 2 deletions rpyc_scheduler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from datetime import datetime
from sqlmodel import SQLModel, Field, Column, Integer, create_engine, Session
from sqlalchemy.dialects import mysql
from config import rpc_config
from .config import rpc_config
from sqlmodel import SQLModel
from typing import Union

engine = create_engine(str(rpc_config.apscheduler_job_store), pool_size=5, max_overflow=10, pool_timeout=30,
engine = create_engine(str(rpc_config['apscheduler_job_store']), pool_size=5, max_overflow=10, pool_timeout=30,
pool_pre_ping=True)


Expand Down
10 changes: 5 additions & 5 deletions rpyc_scheduler/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from datetime import datetime
from loguru import logger
from sqlmodel import text
from utils import Channel, hosts_to_inventory
from config import rpc_config
from models import engine, InventoryHost
from .utils import Channel, hosts_to_inventory
from .config import rpc_config
from .models import engine, InventoryHost


def local_executor(job_id, host, command):
with Channel(rpc_config.redis, job_id=f"{job_id}:{host}") as channel:
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}"})
Expand Down Expand Up @@ -91,7 +91,7 @@ def ansible_task(job_id: str, targets: List[int], ansible_args: Dict[str, Any],
(project_dir / playbook_name).write_text(playbook_content)
ansible_args['playbook'] = playbook_name
# 执行任务,日志通过event_handler写入redis,达到实时写入的效果
with Channel(rpc_config.redis, job_id=job_id) as channel:
with Channel(rpc_config['redis'], job_id=job_id) as channel:
channel.send({'msg': '开始执行任务'})
ansible_msg = "执行主机:" + ','.join(ansible_inventory['all']['hosts'].keys()) + '\r\n'
if ansible_args['module']:
Expand Down