需求:在测试定时任务 能否按时触发时,或者 模拟盘 每日凌晨计算买入/卖出 份额时 ,能够快速测试
方法:通过修改系统时间
修改系统时间命令
date -s "2019-05-01 19:01:55"
查看 当前时间(使用date命令)
注意:为了定时任务能继续运行,设置的时间必须递增(不能从1月2号改为1月1号)
恢复系统时间为网络时间(ubuntu/centos)
1.安装包 ntpdate
# ubuntu
apt-get install ntpdate
# centos
yum -y install ntp ntpdate
2.停止相关服务
service ntp stop
3.设置网络时间
ntpdate cn.pool.ntp.org
4.查看设置结果
date
# -*- coding: utf-8 -*-
"""
(C) rgc
All rights reserved
create time '2020/5/11 17:19'
Module usage:
需求:模拟盘中,定时任务每日凌晨触发,为了在测试中 能快速测试 业务,需要 在保证任务触发时间不变的情况下,保证测试质量和速度
后端技术:定时任务通过 apscheduler 实现,并且在 ubuntu 中运行
解决方法:
注意点:如 我要运行 2019-01-01 至 2019-01-31 时间段内的 模拟盘,则需要 先修改系统时间为 2019-01-01,再运行后端服务,然后根据时间情
况 递增(时间只能增加不能减少【不能从1月2号改为1月1号】)的修改时间
1.ubuntu中 通过 date命令 修改系统时间 命令为: date -s "2019-06-28 19:01:55"
2.修改系统时间为网络时间同步(恢复时间为网络时间):
"""
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
def job():
print('this time is: %s' % datetime.now())
if __name__ == '__main__':
job()
scheduler = BlockingScheduler()
scheduler.add_job(job, 'cron', hour=19, minute=2)
print('ctrl+c or command+c to exit!')
scheduler.start()