Beispiel #1
0
def ping(sender, instance, **kwargs):

    now = datetime.now()

    update_ping = UpdatePing()
    update_ping.created_at = now
    update_ping.pinged_at = now
    # it's our first try. no retries have been done yet.
    update_ping.retry_number = 0

    if INSTANT_PING:
        try:
            req = urlopen(settings.RSSCLOUD_PING_URL, data=urlencode({"url": settings.RSSCLOUD_FEED_URL}))

            res = req.read()

            update_ping.http_code = req.code
            update_ping.response_msg = res

        except HTTPError, e:
            update_ping.http_code = e.code
            update_ping.response_msg = e.read()

        except URLError, e:
            update_ping.http_code = None
            update_ping.response_msg = _("Could not connect")
            (last_ping.retry_number < RETRY_COUNT):

            now = datetime.now()

            try:
                req = urlopen(settings.RSSCLOUD_PING_URL,
                    data=urlencode({"url": settings.RSSCLOUD_FEED_URL}))

                res = req.read()

                http_code = req.code
                response_msg = res

            except HTTPError, e:
                http_code = e.code
                response_msg = e.read()

            except URLError, e:
                http_code = None
                response_msg = _("Could not connect")

            finally:
                update_ping = UpdatePing()
                update_ping.created_at = now
                update_ping.pinged_at = now
                update_ping.retry_number = last_ping.retry_number + 1
                update_ping.http_code = http_code
                update_ping.response_msg = response_msg
                update_ping.save()