python django-background-tasks管理命令未在AWS elasticbeanstalk上运行

zqdjd7g9  于 2023-05-27  发布在  Python
关注(0)|答案(2)|浏览(132)

大家好,我目前正在使用django-background-tasks(https://django-background-tasks.readthedocs.io/en/latest/)在AWS elasticbeanstalk上运行一些后台任务。我最初在main .config容器命令中使用此命令,但在部署中遇到超时错误,因为此管理命令永远不会完成(它将继续运行)。现在,我正在尝试使用建议的方法在elasticbeanstalk(https://aws.amazon.com/premiumsupport/knowledge-center/cron-job-elastic-beanstalk/)上运行cron作业。请看一下我的代码,它没有运行命令。请问有什么问题吗?我只需要命令python manage.py process_tasks继续运行。这在我的本地机器上工作正常,因为我可以轻松地打开另一个终端来启动python manage.py process_tasks命令

files:
    "/etc/cron.d/process_tasks_cron":
        mode: "000644"
        owner: root
        group: root
        content: |
            * * * * * root /usr/local/bin/99_process_tasks.sh

    "/usr/local/bin/99_process_tasks.sh":
        mode: "000755"
        owner: root
        group: root
        content: |
            #!/bin/bash

            date > /tmp/date
            # Your actual script content
            source /var/app/venv/*/bin/activate
            python manage.py process_tasks
            

commands:
    remove_old_cron:
        command: "rm -f /etc/cron.d/*.bak"
bogh5gae

bogh5gae1#

这是代码的工作版本。谢谢,希望它能帮助到外面的人。

files:
        "/etc/cron.d/cron_process":
            mode: "000644"
            owner: root
            group: root
            content: |
                * * * * * root /usr/local/bin/task_process.sh
    
        "/usr/local/bin/task_process.sh":
            mode: "000755"
            owner: root
            group: root
            content: |
                #!/bin/bash
                exec &>> /tmp/cron_capture_log.txt
                date > /tmp/date
                source /var/app/venv/staging-LQM1lest/bin/activate
                cd /var/app/current
                python manage.py process_tasks
               
    
    commands:
        remove_old_cron:
            command: "rm -f /etc/cron.d/cron_process.bak"
mutmk8jj

mutmk8jj2#

你可以在项目的根目录下使用一个非常简单的Procfile:

web: gunicorn --bind 127.0.0.1:8000 --workers=1 --threads=5 your_proj_name.wsgi:application
tasks: python3 manage.py process_tasks

相关问题