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): async def identify(self, path: str):
try: try:
await self.identify(path) await self._identify(path)
await self._client.delete_issue(path) await self._client.delete_issue(path)
except ProviderError as e: except ProviderError as e:
logger.error(e) logger.error(e)

View File

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

View File

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

View File

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

View File

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