| 4 | from convert import to_mp3 |
| 5 | |
| 6 | def main(): |
| 7 | client = MongoClient(os.environ.get('MONGODB_URI')) |
| 8 | db_videos = client.videos |
| 9 | db_mp3s = client.mp3s |
| 10 | # gridfs |
| 11 | fs_videos = gridfs.GridFS(db_videos) |
| 12 | fs_mp3s = gridfs.GridFS(db_mp3s) |
| 13 | |
| 14 | # rabbitmq connection |
| 15 | connection = pika.BlockingConnection( |
| 16 | pika.ConnectionParameters(host='rabbitmq',heartbeat=0) |
| 17 | ) |
| 18 | channel = connection.channel() |
| 19 | |
| 20 | def callback(ch, method, properties, body): |
| 21 | err = to_mp3.start(body, fs_videos, fs_mp3s, ch) |
| 22 | if err: |
| 23 | ch.basic_nack(delivery_tag=method.delivery_tag) |
| 24 | else: |
| 25 | ch.basic_ack(delivery_tag=method.delivery_tag) |
| 26 | |
| 27 | channel.basic_consume( |
| 28 | queue=os.environ.get("VIDEO_QUEUE"), on_message_callback=callback |
| 29 | ) |
| 30 | |
| 31 | print("Waitting for messages, to exit press CTRL+C") |
| 32 | |
| 33 | channel.start_consuming() |
| 34 | |
| 35 | if __name__ == "__main__": |
| 36 | try: |