Skip to main content

SchedulerUtils

Project description

StrategiesManager

这是一个任务管理工具类

格式

配置文件参数:

基础必须字段:

  • name 任务名称,唯一
  • exec_cmd 执行命令
  • exec_path 执行路径,‘/’结尾
  • job_type 任务类型,1 定时任务 2 循环间隔任务 3 保活任务

可选基础字段

  • desc 未使用
  • enable 是否启用,默认启用 1,不启用 0

1)1 定时任务

可选字段:

  • day_of_week 默认"0-6"
  • hour 默认0
  • minute 默认0
  • second 默认0

2)2 循环间隔任务

必须字段:

  • second

3)3 保活任务

保活任务只支持python跟exe等单窗口或单进程文件,就是一个文件一个操作。文件里面另开运行窗口就会被监控忽略。

必须字段:

  • task_name 任务管理器的程序名.后缀

可选字段:

  • second 默认5

注意事项

1)保活任务只支持python跟exe文件,bat文件因为无法得知执行的是什么内容所以无法保活里面执行的内容

2)taskkill+文件.后缀 自定义命令

杀死进程的原理前提是要知道进程的id,可以使用wmic命令根据任务名称或者执行的命令信息找到对应的id。检测进程是否存在也是这个原理。

"exec_cmd": "taskkill xxxx.py"
"exec_cmd": "taskkill xxxx.exe"

3)执行路径要使用斜杠

"exec_path": "C:/Users/Administrator/Desktop/klDataService"

4)任务配置文件使用utf-8编码,不支持中文字符

5)除了执行python命令跟bat文件是启动单独窗口之外其它的命令都在父窗口执行,如果要单独窗口可以在命令前添加‘start’指令

[{
    "exec_cmd": "start xx.exe",
...
}]

6)任务执行的命令

  • 查找任务进程id
    • wmic process where caption="python.exe" get commandline,processid|find "{key}"
  • 杀死进程
    • 根据id杀死进程:taskkill /pid {pid} -f -t
    • 根据任务名杀死进程:taskkill /im {process_name} -f -t

例子

配置文件:task.conf

[
	{
        "name": "KILL_TQ_H_KL_WEB",
        "exec_cmd": "taskkill tq_server.py",
        "exec_path": "./",
        "job_type": 1,
        "day_of_week": "0-6",
        "hour": 5,
        "minute": 10,
        "second": 0,
        "desc": "kill TQ history",
		"enable": 1
    },
	{
        "name": "TQ_H_KL_WEB",
        "exec_cmd": "python tq_server.py -p 10022",
        "exec_path": "C:/Users/Administrator/Desktop/xxxx",
        "job_type": 3,
        "task_name": "tq_server.py",
        "desc": "TQ history service",
		"enable": 1
    },
	{
        "name": "FT_KL_PUSH",
        "exec_cmd": "start xx.exe",
        "exec_path": "C:/Users/Administrator/Desktop/xxxx",
        "job_type": 3,
        "task_name": "xx.exe",
        "desc": "FT kl push",
		"enable": 1
    }
]

例子:

import logging
from rjTools.scheduler_task import doJobs, initLog

initLog(filename='dojob.log', consolelevel=logging.DEBUG, filelevel=logging.ERROR)
doJobs(path='../conf/task.conf')

新增可视化配置界面

from rjTools.scheduler_ui import ShowConfigureUI
ShowConfigureUI('../conf/task.conf')

界面提供编辑task.conf文件功能。 菜单的“开机服务”功能依赖winsw服务,跟执行界面py文件放同一级目录,可以设置定时任务加入到开机服务。

更新日志

  • 2020.11.19

    1. 修改检测任务逻辑
    2. 支持uvicorn启动的python任务
  • 2020.10.20

    1. 修改包名
  • 2020.10.19

    1. 修复小bug,杀死进程exe类型的错误
  • 2020.10.16

    1. 修复小bug
  • 2020.09.18

    1. 完成基本定时任务启动框架

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SchedulerUtils-1.2.2.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SchedulerUtils-1.2.2-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file SchedulerUtils-1.2.2.tar.gz.

File metadata

  • Download URL: SchedulerUtils-1.2.2.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

File hashes

Hashes for SchedulerUtils-1.2.2.tar.gz
Algorithm Hash digest
SHA256 c56f42342d599aa5bd3951cc8bdb8a1009bf4a29bac5c27306eaefc900ccb6b5
MD5 21b3674cd6ac550246b554dedde309f3
BLAKE2b-256 376fc9061e93596d21310e7cc4f62225d135b6388a8b4b3f7dd274b30a458bd4

See more details on using hashes here.

File details

Details for the file SchedulerUtils-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: SchedulerUtils-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

File hashes

Hashes for SchedulerUtils-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94c26e75d5b0d9032b0a3947738c22fd579f61e7423e3bfed0ec1a9adcf9b336
MD5 971cf5f893b6c9d59e6ce06f195c4fb3
BLAKE2b-256 aa8411247722a82ffb4f3869c9456d1432ee1fc764b87b1e31508b54cf8e558d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page