heroku:所有后台任务以数据库错误结束

时间:2016-02-17 20:18:03

标签: django postgresql heroku

我的Heroku项目中有几个背景Django任务。当它们运行时,每个任务都会通过postgres导致错误日志:

2016-02-17T20:08:21Z app[postgres.889]: [DATABASE] could not receive data from client: Connection reset by peer

即使只读取数据库的任务,甚至不写任何内容,也会发生这种情况。

Heroku的帮助页面说:

  

Postgres注意到客户端(您的应用程序)在没有正确结束连接的情况下消失了,并记录了一条消息说明了这一点。

但我的任务没有错误。

例如,

执行此任务:

# -*- coding: utf-8 -*-
"""
just a test task
"""
from __future__ import division, absolute_import, unicode_literals
import os

import django

os.environ['DJANGO_SETTINGS_MODULE'] = 'django_cpa.settings'
django.setup()

from pubscout.models import Campaign


def main():
    active_campaigns = Campaign.objects.filter(active=True).all()
    print(active_campaigns)

if __name__ == '__main__':
    main()

它没有错误地结束,打印所要求的内容,但是heroku日志说:

2016-02-17T20:15:42.998688+00:00 heroku[run.4686]: Starting process with command `python _scheduled/_test_task.py`
2016-02-17T20:15:43.281803+00:00 heroku[run.4686]: State changed from starting to up
2016-02-17T20:15:45Z app[postgres.1001]: [DATABASE] could not receive data from client: Connection reset by peer
2016-02-17T20:15:46.739799+00:00 heroku[run.4686]: State changed from up to complete
2016-02-17T20:15:46.715022+00:00 heroku[run.4686]: Process exited with status 0

出了什么问题?

0 个答案:

没有答案