Ethan Leifer
05/09/2023, 1:06 PM_pool
isn’t avaible
class PostgresResource(ConfigurableResource):
_pool: Pool
_schema: str
async def create_schema(self, schema: str):
async with self._pool.acquire() as conn:
await conn.execute(f"CREATE SCHEMA IF NOT EXISTS {schema};")
async def init_postgres():
pool = await create_pool(
host=POSTGRES_HOST,
port=POSTGRES_PORT,
user=POSTGRES_USER,
password=POSTGRES_PASSWORD,
database=POSTGRES_DB,
)
if pool:
postgres_resource = PostgresResource(
_pool=pool,
_schema=JOB_SCHEMA,
)
await postgres_resource.create_schema(schema=JOB_SCHEMA)
ALL_RESOURCES["postgres"] = postgres_resource
loop = asyncio.get_event_loop()
loop.run_until_complete(init_postgres())
This errors on the create_schema callsean
05/09/2023, 1:35 PMConfigurableResource
objects aren’t just regular python objects, there is an initial routine that happens when they are run as part of a job. The reason _pool
isn’t bound here is because that routine is not getting called because you’re not running this as part of a job.Ethan Leifer
05/09/2023, 2:11 PMEthan Leifer
05/09/2023, 2:12 PMEthan Leifer
05/09/2023, 2:12 PMsean
05/09/2023, 2:59 PMDefinitions
object:
defs = Definitions(
resources = {"postgres": PostgresResource(_pool=pool, _schema=JOB_SCHEMA},
assets=[...],
jobs=[...],
)