Open ale-dd opened 2 years ago
import asyncio
import asyncpg
async def vacuum_job():
conn = await asyncpg.connect(
user='user', password='password', database='database', host='host')
# Execute some queries or tasks
await conn.execute('VACUUM FULL')
await conn.close()
async def async_notice_callback(con, message):
# Handle notices asynchronously here
pass
async def main():
conn = await asyncpg.connect(
user='user', password='password', database='database', host='host',
command_timeout=60, # Adjust the timeout as needed
notice_callback=async_notice_callback # Optional, if you need a notice callback
)
# Create a task for the vacuum job
vacuum_task = asyncio.create_task(vacuum_job())
try:
# Execute some queries or tasks on the main connection
result = await conn.fetch('SELECT * FROM some_table')
print(result)
except asyncio.CancelledError:
# Handle the task cancellation if needed
pass
finally:
await conn.close()
await vacuum_task # Wait for the vacuum job to complete
if __name__ == "__main__":
asyncio.run(main())