Fix matcher/scanner issues

This commit is contained in:
Zoe Roux 2024-04-09 23:17:08 +02:00
parent 8d8e984669
commit e4403cc17c
No known key found for this signature in database
5 changed files with 21 additions and 18 deletions

View File

@ -34,7 +34,7 @@ class Matcher:
async def identify(self, path: str):
try:
await self.identify(path)
await self._identify(path)
await self._client.delete_issue(path)
except ProviderError as e:
logger.error(e)

View File

@ -1,3 +1,4 @@
import asyncio
from dataclasses import dataclass
from dataclasses_json import DataClassJsonMixin
from typing import Literal
@ -34,22 +35,23 @@ class Subscriber:
async def listen(self, scanner: Matcher):
async def on_message(message: AbstractIncomingMessage):
async with message.process():
msg = Message.from_json(message.body)
ack = False
match msg.action:
case "scan":
ack = await scanner.identify(msg.path)
case "delete":
ack = await scanner.delete(msg.path)
case _:
logger.error(f"Invalid action: {msg.action}")
if ack:
await message.ack()
else:
await message.nack(requeue=False)
msg = Message.from_json(message.body)
ack = False
match msg.action:
case "scan":
ack = await scanner.identify(msg.path)
case "delete":
ack = await scanner.delete(msg.path)
case _:
logger.error(f"Invalid action: {msg.action}")
if ack:
await message.ack()
else:
await message.reject()
# Allow up to 20 scan requests to run in parallel on the same listener.
# Since most work is calling API not doing that is a waste.
await self._channel.set_qos(prefetch_count=20)
await self._queue.consume(on_message)
await asyncio.Future()

View File

@ -26,7 +26,7 @@ logger = getLogger(__name__)
class TheMovieDatabase(Provider):
def __init__(
self,
languages,
languages: list[str],
client: ClientSession,
api_key: str,
xem: TheXem,

View File

@ -20,6 +20,7 @@ class Provider:
if not languages:
print("Missing environment variable 'LIBRARY_LANGUAGES'.")
exit(2)
languages = languages.split(",")
providers = []
from providers.idmapper import IdMapper

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
import asyncio
import matcher
import scanner
asyncio.run(matcher.main())
asyncio.run(scanner.main())