bugfix: 修改定时任务错误

This commit is contained in:
chenwj113 2024-04-28 22:52:09 +08:00
parent bd5580ee4b
commit 16c7b2405d
5 changed files with 14 additions and 3 deletions

View File

@ -27,4 +27,4 @@ COPY . /app
WORKDIR /app
CMD ["python", "main.py"]
CMD ["python", "-u", "main.py"]

View File

@ -5,5 +5,7 @@ services:
image: "schedule_tasks"
container_name: "schedule_tasks"
restart: always
extra_hosts:
- "host.docker.internal:172.17.0.1"
# ports:
# - "18000:8000"

View File

@ -32,7 +32,7 @@ class Lottery(object):
raise Exception("未知的lottery_type")
def _get_db_session(self):
_engine = create_engine("mysql+pymysql://root:Chenweijia113!@172.17.0.1/lottery?charset=utf8", pool_pre_ping=True, pool_recycle=3600)
_engine = create_engine("mysql+pymysql://root:Chenweijia113!@host.docker.internal/lottery?charset=utf8", pool_pre_ping=True, pool_recycle=3600)
_DbSession = sessionmaker(bind=_engine)
return _DbSession()

View File

@ -1,4 +1,5 @@
import time
from datetime import datetime
from retrying import retry
from schedule import every, repeat, run_pending
from requests_html import HTML, HTMLSession
@ -41,14 +42,20 @@ def get_data_job(lottery_type='pls', issue=None):
@repeat(every().day.at("00:01"))
def pls_job():
time_now = datetime.now()
print(f"当前任务运行时间为: {time_now.strftime('%H:%M:%S')}")
get_data_job(lottery_type='pls')
@repeat(every().day.at("00:02"))
def plw_job():
time_now = datetime.now()
print(f"当前任务运行时间为: {time_now.strftime('%H:%M:%S')}")
get_data_job(lottery_type='plw')
@repeat(every().day.at("00:03"))
def sd_job():
time_now = datetime.now()
print(f"当前任务运行时间为: {time_now.strftime('%H:%M:%S')}")
get_data_job(lottery_type='sd')
while True:

View File

@ -6,3 +6,5 @@ retry==0.9.2
retrying==1.3.4
schedule==1.2.0
SQLAlchemy==2.0.11
lxml==4.9.2
cryptography==42.0.5