我在django/python中有一个crontab,代码如下。它同时发送多个通知,而不是发送单个通知。有什么问题吗?
`def send_statistics():
today = date.today()
yesterday = today - timedelta(days=1)
try:
if StatisticModel.objects.filter(date=yesterday).exists():
stat = StatisticModel.objects.get(date=yesterday)
if not stat.is_send:
text = "some text"
send_message_telegram(text, SEND_STATISTIC_GROUP_ID)
stat.is_send = True
stat.save()
time.sleep(100)
else:
StatisticModel.objects.create(is_send=True, date=yesterday)
text = f"<b>*******HISOBOT*******</b>\n" \
send_message_telegram(text, SEND_STATISTIC_GROUP_ID)
time.sleep(100)
except:
send_message_telegram
def start():
scheduler = BackgroundScheduler({'apscheduler.timezone': 'Asia/Tashkent'})
scheduler.add_job(send_statistics, 'cron', hour=9)
scheduler.start()`
1条答案
按热度按时间e37o9pze1#
这是因为,Gunicorn工人同时称之为Cron作业。所以它才发了多条通知。作为一种解决方案,您可以使用缓存。