Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import time
- from datetime import datetime
- import pika
- from flockos import SendAs
- from flockos import chat
- def send_message_to_floke(queue_size):
- # SendAs позволяет отправлять сообщение от любого имени и с какой-то картинкой в профиле
- # Поищи в доках как получить bot_token и user_guid
- send_as_hal = SendAs(name='HAL-9000',
- profile_image='https://pbs.twimg.com/profile_images/1788506913/HAL-MC2_400x400.png')
- message_id = chat.send_message(token=bot_token, to=user_guid,
- text=f'Queue size {queue_size} at {str(datetime.now())}',
- send_as=send_as_hal)
- def check_queue_size(host, timeout=5):
- # establish connection with RabbitMQ server
- connection = pika.BlockingConnection(pika.ConnectionParameters(host))
- try:
- channel = connection.channel()
- channel.queue_declare(queue="task_queue", durable=True)
- while True:
- rabbit_queue = channel.queue_declare(queue="task_queue", durable=True, passive=True)
- queue_size = rabbit_queue.method.message_count
- if queue_size > 0:
- send_message_to_floke(queue_size)
- time.sleep(timeout)
- finally:
- connection.close()
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(description='Queue size checker on host')
- parser.add_argument('host', help='host address')
- parser.add_argument('--timeout', help='timeout between requests')
- args = parser.parse_args()
- check_queue_size(host=args.host, timeout=args.timeout)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement