the-superpirate 43be16e4bc - [nexus] Update schema
- [nexus] Remove outdated protos
  - [nexus] Development
  - [nexus] Development
  - [nexus] Development
  - [nexus] Development
  - [nexus] Development
  - [nexus] Refactor views
  - [nexus] Update aiosumma
  - [nexus] Add tags
  - [nexus] Development
  - [nexus] Update repository
  - [nexus] Update repository
  - [nexus] Update dependencies
  - [nexus] Update dependencies
  - [nexus] Fixes for MetaAPI
  - [nexus] Support for new queries
  - [nexus] Adopt new versions of search
  - [nexus] Improving Nexus
  - [nexus] Various fixes
  - [nexus] Add profile
  - [nexus] Fixes for ingestion
  - [nexus] Refactorings and bugfixes
  - [idm] Add profile methods
  - [nexus] Fix stalled nexus-meta bugs
  - [nexus] Various bugfixes
  - [nexus] Restore IDM API functionality

GitOrigin-RevId: a0842345a6dde5b321279ab5510a50c0def0e71a
2022-09-02 19:15:47 +03:00

42 lines
1.1 KiB
Python

from __future__ import annotations
import asyncio.exceptions
from typing import Iterable
from aiokit import AioThing
from izihawa_utils.importlib import instantiate_object
from tenacity import (
retry,
retry_if_exception_type,
wait_fixed,
)
class Processor(AioThing):
def filter(self, message) -> bool:
return True
async def process(self, message):
return message
async def process_bulk(self, messages: Iterable):
for message in messages:
await self.process(message)
class ActionProcessor(Processor):
def __init__(self, actions, filter):
super().__init__()
self.actions = [instantiate_object(action) for action in actions]
self.filter_object = instantiate_object(filter)
self.starts.append(self.filter_object)
self.starts.extend(self.actions)
def filter(self, message) -> bool:
return self.filter_object.filter(message)
@retry(retry=retry_if_exception_type(asyncio.exceptions.TimeoutError), wait=wait_fixed(5))
async def process(self, message):
for action in self.actions:
message = await action.do(message)