我有一系列django自定义命令,我正在尝试通过cron-tab通过cron.py脚本自动执行。
class Command(BaseCommand):
def add_arguments(self, parser):
pass
def handle(self, *args, **options):
#init cron
cron = CronTab(user='dtorr')
#add new cron job
job = cron.new(command='python /home/dtorr/myproject/pol/sanct/management/commands/congress_dl.py >>/tmp/out.txt 2>&1')
job1 = cron.new(command='python /home/dtorr/myproject/pol/sanct/management/commands/congress_extract.py >>/tmp/out.txt 2>&1')
#job settings
job.minute.every(120)
job1.minute.every(120)
cron.write()
当我在终端中使用crontab -l检查cron作业是否已加载时,命令会出现,但似乎没有在执行。我是否需要以某种方式在这些命令中引用我的virtualenv?我想念什么?这些脚本下载文件,但似乎未在执行。我已验证命令是否可以正常工作。某些命令似乎可以运行,但是以下django命令失败:
输出文件显示:
Traceback (most recent call last):
File "/home/architect/myprojectdir/sanctions/management/commands/cong_transfer.py", line 19, in <module>
from sanct.models import Summary, Status