Skip to content

Instantly share code, notes, and snippets.

View DFilyushin's full-sized avatar
🍓
Python, MSA, Rabbitmq

Dmitriy Filyushin DFilyushin

🍓
Python, MSA, Rabbitmq
View GitHub Profile
import asyncio
async def run_periodically(wait_time, func, *args):
"""
Helper for schedule_task_periodically.
Wraps a function in a coroutine that will run the
given function indefinitely
:param wait_time: seconds to wait between iterations of func
:param func: the function that will be run
:param args: any args that need to be provided to func
@DFilyushin
DFilyushin / rabbit_mq_consumer.py
Last active December 9, 2020 05:47
rabbit_mq_consumer
import asyncio
import aio_pika
import time
import sys
async def process_message(message: aio_pika.IncomingMessage):
async with message.process():
# worker_name = sys.argv[1]
print(message.body, 'queue: result', message.routing_key)
@DFilyushin
DFilyushin / wsl_compact_drive.cmd
Created August 5, 2021 11:26
wsl_compact_drive.cmd
wsl --shutdown
diskpart
# open window Diskpart
select vdisk file="C:\WSL-Distros\…\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit
@DFilyushin
DFilyushin / logger_helper.py
Created August 26, 2021 05:44
Disable access log for FastAPI
class EndpointFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
return record.getMessage().find("/endpoint") == -1
# Filter out /endpoint
logging.getLogger("uvicorn.access").addFilter(EndpointFilter())
async def callback_sessions(msg, topic):
pass
def consumer_factory():
for t in topics:
yield AsyncJafkaConsumer(topic=t, ..., callback=partial(callback_sessions, topic=t))
def run():
for c in consumer_factory():
asyncio.ensure_future(c.consume())