2021-01-04 09:35:31 +01:00
|
|
|
from typing import (
|
|
|
|
Any,
|
|
|
|
AsyncIterable,
|
|
|
|
Iterable,
|
|
|
|
)
|
|
|
|
|
|
|
|
from library.aiopostgres.pool_holder import AioPostgresPoolHolder
|
|
|
|
from nexus.ingest.jobs.base import BaseJob
|
|
|
|
|
|
|
|
|
|
|
|
class SelfFeedJob(BaseJob):
|
|
|
|
name = 'self-feed-job'
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
database: dict,
|
|
|
|
sql: str,
|
|
|
|
actions: Iterable[dict],
|
|
|
|
sinks: Iterable[dict],
|
|
|
|
):
|
|
|
|
super().__init__(actions=actions, sinks=sinks)
|
|
|
|
self.sql = sql
|
|
|
|
self.pool_holder = AioPostgresPoolHolder(
|
2022-03-28 16:39:36 +02:00
|
|
|
conninfo=f'dbname={database["database"]} '
|
2021-01-04 09:35:31 +01:00
|
|
|
f'user={database["username"]} '
|
|
|
|
f'password={database["password"]} '
|
|
|
|
f'host={database["host"]}',
|
|
|
|
)
|
|
|
|
self.waits.append(self.pool_holder)
|
|
|
|
|
|
|
|
async def iterator(self) -> AsyncIterable[Any]:
|
2022-03-28 16:39:36 +02:00
|
|
|
async for row in self.pool_holder.iterate(self.sql):
|
2021-01-04 09:35:31 +01:00
|
|
|
yield row
|