通过 docker-compose 调用 python 脚本的 Crontab 未执行

Crontab that calls python script via docker-compose not executing

我有一个 crontab 设置为 运行 从 docker-compose 命令调用的 python 脚本:

* * * * * cd path/to/repo && docker-compose run worker python -c "from directory.module import test_function; test_function()"

模块 & test_function 如下所示:

import logger

def test_function():
    logger.info('Hello')

docker 容器已启动并且 运行正在运行。但是,当我去检查我的日志文件时,没有任何内容写入其中。我不确定我需要做什么才能让它正常工作。

因此,我创建了一个 shell 脚本 (test_cronjob.sh) 来 运行 我需要的命令。

#!/bin/bash

PATH=/usr/local/bin/
docker-compose -f /full/path/to/docker-compose.yml run worker python -c "from directory.module import test_function; test_function()"

并编辑了我的 crontab -e:

* * * * * /bin/sh /full/path/to/test_cronjob.sh

或者只是简单地编辑 crontab -e 而没有 shell 脚本,如下所示:

* * * * * PATH=/usr/local/bin/ docker-compose -f /full/path/to/docker-compose.yml run worker python -c "from directory.module import test_function; test_function()"