每日 cron 运行 因超过最大 运行 时间而终止

daily cron run terminated as it exceeded max run time

我不知道为什么我的 cron 运行ning 20 分钟就终止了。在 openshift 上,如果你 运行 cron,它会在 5 分钟后被杀死。如果你 运行 使用 nohup,它会在 20 分钟后被杀死。
这是我在 cron_daily 上的错误日志。文件 update_dave_list 是 运行 宁 20 分钟:

Thu Nov 19 03:08:08 EST 2015: START daily cron run
__________________________________________________________________________
/var/lib/openshift/55a000094/app-root/runtime/repo//.openshift/cron/daily/update_dave_list:
WARNING:py.warnings:/var/lib/openshift/55a0000094/python/virtenv/lib/python2.7/site-packages/django_crontab-0.6.0-py2.7.egg/django_crontab/crontab.py:13: RemovedInDjango19Warning: django.uti$
  from django.utils.importlib import import_module
/usr/libexec/openshift/cartridges/cron/bin/cron_runjobs.sh: line 114: 181616 Killed                  $executor "$SCRIPTS_DIR"
Warning: daily cron run terminated as it exceeded max run time
__________________________________________________________________________
Thu Nov 19 03:28:09 EST 2015: END daily cron run - status=137
__________________________________________________________________________

问题是 update_dave_list 到 运行 只需要 ~20 秒: update_dave_list内容:

#!/bin/bash
date
nohup /var/lib/openshift/55000094/python/virtenv/bin/python /var/lib/openshift/55000094/app-root/runtime/repo/wsgi/digrin/manage.py crontab run 18e10bf4fb745d8a480230a3 # update dave lists
date

输出:

Št nov 19 03:43:47 EST 2015
nohup: ignoring input and appending output to `nohup.out'
Št nov 19 03:44:05 EST 2015

问题还在于,如果有一个被杀死,我的其他每日 crons 中的 none 是 运行。 哦,这是代码,以防你想知道我 运行宁 20 秒:

def update_dave_list():
    # if settings.ON_OPENSHIFT:
    response = urlopen("http://www.dripinvesting.org/tools/U.S.DividendChampions.xls")
    excell = xlrd.open_workbook(file_contents=response.read())
    for sheet in range(0,3): #for champions, challengers and contenders
        worksheet = excell.sheet_by_index(sheet)
        list, created = List.objects.get_or_create(name=worksheet.name, short_name=worksheet.name,
                                                   source="http://www.dripinvesting.org/tools/tools.asp")
        num_rows = worksheet.nrows - 1
        curr_row = 5
        symbol_list = []
        while curr_row < num_rows:
            curr_row += 1
            symbol = worksheet.cell(curr_row, 1)
            if symbol.ctype != 1: #break if you are out of symbol
                break
                #print  cell.value.replace(".", "-")
            symbol_list.append(unify_symbol(symbol.value))
            industry = worksheet.cell(curr_row, 2)
            sector = worksheet.cell(curr_row, 77)
            years = worksheet.cell(curr_row, 3)
            try:
                list_stock, created = ListStock.objects.get_or_create(stock=Stock.objects.get(symbol=unify_symbol(symbol.value)))
            except ObjectDoesNotExist:
                AddStock.objects.get_or_create(symbol=unify_symbol(symbol.value))
                continue
            list_stock.industry = industry.value
            list_stock.years_paying = years.value
            if sector.ctype == 1:
                if list_stock.stock.sector == None:
                    sector_obj, created = Sector.objects.get_or_create(name=sector.value)
                    list_stock.stock.sector = sector_obj
                    list_stock.stock.save()
            list_stock.save()
            #add stocks to list
            list.stocks.add(list_stock)
        #delete removed stocks
        for list_stock in list.stocks.all():
            if list_stock.stock.symbol not in symbol_list:
                list.stocks.remove(list_stock)
    return

但它可能不依赖于代码,因为如果我 运行 我的 cron 文件 (./update_dave_list) 它会在 20 秒内完成,而当 运行 通过 cron 它不会完成.知道这里可能有什么问题吗?


编辑 1: 所以我试着像这样注释掉文件 update_dave_list

#!/bin/bash
#/var/lib/openshift/55a0310e4382ec4b84000094/python/virtenv/bin/python /var/lib/openshift/55a0310e4382ec4b84000094/app-root/runtime/repo/wsgi/digrin/manage.py crontab run 18e10bf4fb92741b69745d8a480230a3 # update dave lists

我在 openshift 上的每日 cron 文件夹如下所示:

drwx------. 2 55a00094 55a00094 4096 nov 22 17:55 .
drwx------. 7 55a00094 55a00094 4096 nov 22 17:39 ..
-rw-------. 1 55a00094 55a00094    0 nov 22 17:37 .gitignore
-rwxr-xr-x. 1 55a00094 55a00094  236 nov 22 17:37 update_dave_list
-rwxr-xr-x. 1 55a00094 55a00094  235 nov 22 17:37 update_dgr
-rwxr-xr-x. 1 55a00094 55a00094  244 nov 22 17:37 update_ex_dividends
-rwxr-xr-x. 1 55a00094 55a00094  250 nov 22 17:37 update_frequency
-rwxr-xr-x. 1 55a00094 55a00094  236 nov 22 17:37 update_industry
-rwxr-xr-x. 1 55a00094 55a00094  472 nov 22 17:37 update_stocks
-rwxr-xr-x. 1 55a00094 55a00094  243 nov 22 17:37 update_years_paying
-rwxr-xr-x. 1 55a00094 55a00094  252 nov 22 17:37 watcher

在我注释掉 dave 列表更新后,这是来自 cron_daily.log:

的日志
__________________________________________________________________________
Mon Nov 23 03:25:54 EST 2015: START daily cron run
__________________________________________________________________________
/usr/libexec/openshift/cartridges/cron/bin/cron_runjobs.sh: line 114: 28445 Killed                  $executor "$SCRIPTS_DIR"
Warning: daily cron run terminated as it exceeded max run time
__________________________________________________________________________
Mon Nov 23 03:45:54 EST 2015: END daily cron run - status=137
__________________________________________________________________________

我认为这意味着我的文件 none 是 运行 并且错误在 cron_runjobs.sh 中。但我没有得到 openshift 的支持,报告错误也无济于事(我几周前报告过一个,但还没有更新)。奇怪的是我的每日 cron 不工作,每小时 cron 工作正常。


编辑2: 我试图重新启动 cron cartridge:

rhc cartridge remove cron -a <app>
rhc cartridge add cron -a <app>

没有帮助:

__________________________________________________________________________
Tue Nov 24 03:12:47 EST 2015: START daily cron run
__________________________________________________________________________
/usr/libexec/openshift/cartridges/cron/bin/cron_runjobs.sh: line 114: 211644 Killed                  $executor "$SCRIPTS_DIR"
Warning: daily cron run terminated as it exceeded max run time
__________________________________________________________________________
Tue Nov 24 03:32:47 EST 2015: END daily cron run - status=137
__________________________________________________________________________

我不知道现在该做什么。如果启动每日 cron 中的文件,它看起来像这样:

__________________________________________________________________________
Mon Nov 23 13:01:05 EST 2015: START hourly cron run
__________________________________________________________________________
/var/lib/openshift/55a000094/app-root/runtime/repo//.openshift/cron/hourly/add_stocks:
...

但是日常 cron 不会 运行 日常目录中的任何文件。

没有足够的声誉来添加评论,所以我必须添加一个答案作为评论。

以防万一,您确定 urlopen() 可以在 OpenShift 上获取 xls 吗?也许防火墙或其他东西阻止了这个请求。您应该在代码中添加更多日志。

好的,我想我找到问题所在了。
首先,我可以像这样强制 运行 每日 cron:

/usr/libexec/openshift/cartridges/cron/bin/cron_runjobs.sh daily

这是我每日 cron 的日志:

__________________________________________________________________________
Wed Nov 25 03:24:19 EST 2015: START daily cron run
__________________________________________________________________________
/var/lib/openshift/55a000094/app-root/runtime/repo//.openshift/cron/daily/update_dave_list:
WARNING:py.warnings:/var/lib/openshift/55a000094/python/virtenv/lib/python2.7/site-packages/django_crontab-0.6.0-py2.7.egg/django_crontab/crontab.py:13: RemovedInDjango19Warning: django.uti$
  from django.utils.importlib import import_module
Wed Nov 25 03:24:38 EST 2015
/usr/libexec/openshift/cartridges/cron/bin/cron_runjobs.sh: line 114: 375681 Killed                  $executor "$SCRIPTS_DIR"
Warning: daily cron run terminated as it exceeded max run time

我认为问题出在 update_dave_list。但是当我像这样在 update_dave_list 文件中打印日期时:

#!/bin/bash
/var/lib/openshift/55a000094/python/virtenv/bin/python /var/lib/openshift/55a000094/app-root/runtime/repo/wsgi/digrin/manage.py crontab run 18e10bf4fb92741b69745d8a480230a3 # update dave lists
date

我意识到日期打印在日志中 -> update_dave_list 成功完成! (Wed Nov 25 03:24:38 EST 2015) 所以问题一定是在 openshift 中,不会结束 update_dave_list 进程或正确拾取另一个文件,但它会在成功完成后写入日志(这种情况从未发生过)。第二个想法更合乎逻辑。我有一个文件,在我的本地主机上在 20 分钟内完成,但在 openshift 上它没有按时完成。我通过将这个长的 运行ning cron 拆分为多个部分(每小时 cron)来解决这个问题,现在看起来 运行s ok.
感谢帮助!我知道这里没有多少人使用 Openshift,而且没有很多日志和信息,调试起来并不容易!再次感谢您的宝贵时间和帮助!