我正在尝试将 Huey 文档中建议的代码组织实施到现有应用程序中,并遵循简单的示例。目标是构建一个每天凌晨 3:00 运行任务的 crontab。
我打开了两个终端选项卡,第一个是消费者运行示例中的脚本:
PYTHONPATH=.:$PYTHONPATH
export WORKER_CLASS=${1:-thread}
huey_consumer.py main.huey --workers=4 -k $WORKER_CLASS -C -S
然后,在另一个选项卡中,我运行 main.py 脚本:
python main.py
配置文件
from huey import SqliteHuey
huey = SqliteHuey(filename='/tmp/huey.db')
任务.py
from config import huey
# Note that this time is 1 minute before whenever I'm debugging.
# I'm using the 3 am example as what we're aiming for in our final product.
@huey.periodic_task(crontab(minute='0', hour='3'))
def run_this_function():
system = New_Class() # Class instantiation since there's a bunch that happens when a new class is set up
system.run_method # Runs a bunch of methods from the class in one location
主文件
from config import huey
from tasks import run_this_function
def main:
run_this_function()
if __name__ == "__main__":
main()
该任务立即运行,并且由于我对 Huey 是全新的,不确定我可能会缺少什么以使其按计划工作。我尝试了很多 crontab 组合,不确定是否存在挑战,或者我如何run_this_function
在main
方法中调用。任何帮助表示赞赏!