thinkphp5+python.apscheduler实现计划任务
1.thinkphp5配置自定义命令行
/application/console/command
namespace app\console\command; use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use app\autotask\task; class Test extends Command{ /**
* 定义命令
* 命令名称是 test
*/
protected function configure()
{
$this->setName('test')->setDescription('Here is the market test task ');
}
/**
* 命令执行的内容
* @param Input $input
* @param Output $output
*/
protected function execute(Input $input, Output $output)
{
$output->writeln("StartCommand Test:");
$object = new \app\autotask\task\Test();
$object->run();
$output->writeln("End Test..");
}
}
2.python安装APScheduler是Python的一个定时任务框架,可以很方便的满足用户定时执行或者周期执行任务的需求,它提供了基于日期date、固定时间间隔interval 、以及类似于Linux上的定时任务crontab类型的定时任务。并且该框架不仅可以添加、删除定时任务,还可以将任务存储到数据库中,实现任务的持久化,所以使用起来非常方便。
更多了解 https://pypi.org/project/APScheduler/
pip install apscheduler
#!/user/bin/env python
#
# -*- coding: UTF-8 -*- import time
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import os logger = logging.getLogger()
logger.setLevel(logging.DEBUG) fileHandler = logging.FileHandler('./log/task.log', mode='w', encoding='UTF-8')
fileHandler.setLevel(logging.NOTSET) formatter = logging.Formatter('%(asctime)s - %(message)s')
fileHandler.setFormatter(formatter) logger.addHandler(fileHandler) def task():
output = os.popen('php think test')
logger.info(output)
print output.read() if __name__ == '__main__':
scheduler = BlockingScheduler()
scheduler.add_job(task, 'cron', hour='9-22', second = '*/1')
#scheduler.add_job(task, 'cron', hour='9-22', second = '*/1')
scheduler.add_job(task, 'cron', hour='9-22', second = '*/1')
scheduler.add_job(task, 'cron', hour = 22,minute = 1)
scheduler.add_job(task, 'interval', minutes=1)
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try:
scheduler.start()
except (KeyboardInterrupt, SystemExit):
pass
thinkphp5+python.apscheduler实现计划任务的更多相关文章
- Python核心团队计划2020年停止支持Python2,NumPy宣布停止支持计划表
Python核心团队计划在2020年停止支持Python 2.NumPy项目自2010年以来一直支持Python 2和Python 3,并且发现支持Python 2对我们有限的资源增加了负担:因此,我 ...
- python APScheduler
简介 APScheduler基于Quartz的一个Python定时任务框架,实现了Quartz的所有功能,使用起来十分方便.提供了基于日期.固定时间间隔以及crontab类型的任务,并且可以持久化任务 ...
- python APScheduler模块
简介 一般来说Celery是python可以执行定时任务, 但是不支持动态添加定时任务 (Django有插件可以动态添加), 而且对于不需要Celery的项目, 就会让项目变得过重. APSchedu ...
- python性能测试大致计划
hi guy: 如果注意到创建时间,那就对了.这份文章,是我学习Python一个月以后动手写的. 写下这份计划以后,只完成了第一步,其中磕磕绊绊编写代码的过程,很大一部分时间是完全用txt写的 ...
- python apscheduler的使用
from apscheduler.schedulers.blocking import BlockingSchedulerfrom datetime import datetime def my_jo ...
- windows开机自启python服务(任务计划程序+bat脚本)
需求:根据上海某银行 的需求,使用到获取数据服务的软件 只能在windows上运行,所以有 windows系统开机用户登录后自启动python flask服务 的需求: 相关工具:win10系统中,使 ...
- Python - 时间相关与计划任务
Python - 时间处理与定时任务 1.计算明天和昨天的日期 # 获取今天.昨天和明天的日期 # 引入datetime模块 import datetime #计算今天的时间 today = date ...
- 【head first python】学习计划
1 初识Python:人人都爱列表 2 共享你的代码:函数模块 3 文件与异常:处理错误 4 持久存储:数据保存到文件 5 推导数据:处理数据! 6 定制数据对象:打包代码与数据 7 Web开发:集成 ...
- Python百题计划
一.基础篇 想要像类似执行shell脚本一样执行Python脚本,需要在py文件开头加上什么?KEY:#!/usr/bin/env python Python解释器在加载 .py 文件中的代码时,会对 ...
随机推荐
- PAT A1034 Head Of Gang
用并查集分割团伙,判断输出~ #include<bits/stdc++.h> using namespace std; ; },weight[maxn]; unordered_map< ...
- if,while,for循环
目录 if条件 while循环 for循环 拓展知识点 if条件 if 条件: code elif 条件: code else: code # 三元运算符 x = 10 y = 20 print(y ...
- 吴裕雄--天生自然PythonDjangoWeb企业开发:解决Pythonno module named "XX"问题
在项目中加入 sys.path.append('你的django项目路径') sys.path.append('python的site-packages路径')
- 使用阿里云服务器配置frp实现Windows系统RDP内网穿透
1.frp服务器采用阿里云ecs的centos7.5系统,客户端是台windows10的系统,做一个RDP服务的内网穿透用. 2.首先下载frp到服务器(链接:https://github.com/f ...
- 正确使用 Android 的 Theme 和 Style
原文:http://www.tuicool.com/articles/ZjEZFj Android 5.0 可以给一个 View 单独设置一个 theme 了,其主要用途就是用在 ToolBar 上, ...
- NOIP2019 旅行
注意!注意!前方高能!本题卡常!!! 我们发现,所有的狗血剧情都在告诉我们,树的话直接dfs就出来了 那么基环树呢? 其实只要暴力删边,理论上的复杂度是可以过的qwq 但是删哪条边呢? 这里要引出一个 ...
- 32 commons-lang包学习
maven依赖 <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lan ...
- vue中 el [$el] 的理解
<template> <div class="a"> <div class="basic" ref="ba"& ...
- 设计模式课程 设计模式精讲 12-2 适配器模式coding
1 重要 1.1 类适配器和对象适配器最大的区别 2 代码演练 2.1 代码演练1(类适配器模式) 2.2 代码演练2(对象适配模式) 2.3 代码演练3(具体应用场景) 1 重要 1.1 类适配器和 ...
- Python字符乱码
content = b'{"log_id": 5507183146687669657, "words_result_num": 2, "words_r ...