mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-23 15:08:00 +00:00
Compare commits
1 commit
6df13c71f3
...
cc76256b12
Author | SHA1 | Date | |
---|---|---|---|
cc76256b12 |
|
@ -243,10 +243,11 @@ class SqlCache(Cache):
|
||||||
if self._db is None:
|
if self._db is None:
|
||||||
raise RuntimeError("Database has not been setup")
|
raise RuntimeError("Database has not been setup")
|
||||||
|
|
||||||
date = Date.new_utc() - timedelta(days = days)
|
limit = Date.new_utc() - timedelta(days = days)
|
||||||
|
params = {"limit": limit.timestamp()}
|
||||||
|
|
||||||
with self._db.session(True) as conn:
|
with self._db.session(True) as conn:
|
||||||
with conn.execute("DELETE FROM cache WHERE updated < :limit", {"limit": date}):
|
with conn.execute("DELETE FROM cache WHERE updated < :limit", params):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,9 @@ class HttpClient:
|
||||||
data = await resp.text()
|
data = await resp.text()
|
||||||
|
|
||||||
if resp.status not in (200, 202):
|
if resp.status not in (200, 202):
|
||||||
|
logging.verbose('Received error when requesting %s: %i', url, resp.status)
|
||||||
|
logging.debug(data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
error = json.loads(data)["error"]
|
error = json.loads(data)["error"]
|
||||||
|
|
||||||
|
@ -220,12 +223,16 @@ class HttpClient:
|
||||||
logging.verbose('Sending "%s" to %s', mtype, url)
|
logging.verbose('Sending "%s" to %s', mtype, url)
|
||||||
|
|
||||||
async with self._session.post(url, headers = headers, data = body) as resp:
|
async with self._session.post(url, headers = headers, data = body) as resp:
|
||||||
if resp.status not in (200, 202):
|
# Not expecting a response, so just return
|
||||||
raise HttpError(
|
if resp.status in {200, 202}:
|
||||||
resp.status,
|
logging.verbose('Successfully sent "%s" to %s', mtype, url)
|
||||||
await resp.text(),
|
return
|
||||||
headers = {k: v for k, v in resp.headers.items()}
|
|
||||||
)
|
logging.error('Received error when pushing to %s: %i', url, resp.status)
|
||||||
|
logging.debug(await resp.read())
|
||||||
|
logging.debug("message: %s", body.decode("utf-8"))
|
||||||
|
logging.debug("headers: %s", json.dumps(headers, indent = 4))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
async def fetch_nodeinfo(self, domain: str, force: bool = False) -> Nodeinfo:
|
async def fetch_nodeinfo(self, domain: str, force: bool = False) -> Nodeinfo:
|
||||||
|
|
|
@ -5,7 +5,6 @@ import traceback
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientConnectionError, ClientSSLError
|
from aiohttp.client_exceptions import ClientConnectionError, ClientSSLError
|
||||||
from asyncio.exceptions import TimeoutError as AsyncTimeoutError
|
from asyncio.exceptions import TimeoutError as AsyncTimeoutError
|
||||||
from blib import HttpError
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from multiprocessing import Event, Process, Queue, Value
|
from multiprocessing import Event, Process, Queue, Value
|
||||||
from multiprocessing.queues import Queue as QueueType
|
from multiprocessing.queues import Queue as QueueType
|
||||||
|
@ -95,9 +94,6 @@ class PushWorker(Process):
|
||||||
try:
|
try:
|
||||||
await self.client.post(item.inbox, item.message, item.instance)
|
await self.client.post(item.inbox, item.message, item.instance)
|
||||||
|
|
||||||
except HttpError as e:
|
|
||||||
logging.error('HTTP Error when pushing to %s: %i %s', item.inbox, e.status, e.message)
|
|
||||||
|
|
||||||
except AsyncTimeoutError:
|
except AsyncTimeoutError:
|
||||||
logging.error('Timeout when pushing to %s', item.domain)
|
logging.error('Timeout when pushing to %s', item.domain)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue