簡體   English   中英

在 Heroku 上部署時,每天在特定時間運行函數的 Python 腳本不起作用

[英]Python script to run a function at a specific time every day does not work when deployed on Heroku

我正在嘗試使用 python 創建一個電報機器人,它將每天在特定時間運行一個函數。

from operator import ge
import schedule
import telebot
import time
from threading import Thread
from time import sleep




bot = telebot.TeleBot("bot token")
jay = chat_id

def test_message():
    bot.send_message(jay, "This is test")


def schedule_checker():
    while True:
        schedule.run_pending()
        time.sleep(1)



if __name__ == "__main__":
    # Create the job in schedule.
    schedule.every().day.at("03:58").do(test_message)

    Thread(target=schedule_checker).start() 

當我通過終端在 VScode 上運行它時,它可以工作,但是當我在 Heroku 上部署機器人時,它不起作用。 我很確定我正確地部署了它。 如果這是一個愚蠢的問題(我剛剛開始我的編碼之旅),將不勝感激任何建議,提前感謝您並道歉。

我意識到部署在 Heroku 上的機器人仍在發送消息,但它在錯誤的時間發布。 我意識到它使用的是UTC時間。 我編輯了代碼以將其更改為 UTC 時間,現在它在正確的時間發布。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM