From 1c81d0d2385a4ce0c945c6070bfde0fe6587e53c Mon Sep 17 00:00:00 2001 From: James <james@sourcefabric-DX4840.(none)> Date: Thu, 11 Aug 2011 16:20:20 -0400 Subject: [PATCH] CC-2631: Convert pypo to accept commands from RabbitMQ - initial commit --- airtime_mvc/application/models/RabbitMq.php | 4 +++- python_apps/pypo/pypofetch.py | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index e50590622..514f8aecf 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -31,7 +31,9 @@ class RabbitMq $EXCHANGE = 'airtime-schedule'; $channel->exchange_declare($EXCHANGE, 'direct', false, true); - $data = json_encode(Schedule::GetScheduledPlaylists()); + $temp['event_type'] = "update_schedule"; + $temp['schedule'] = Schedule::GetScheduledPlaylists(); + $data = json_encode($temp); $msg = new AMQPMessage($data, array('content_type' => 'text/plain')); $channel->basic_publish($msg, $EXCHANGE); diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 9bd165653..8ce94420e 100755 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -48,7 +48,13 @@ def handle_message(body, message): logger = logging.getLogger('fetch') global SCHEDULE_PUSH_MSG logger.info("Received schedule from RabbitMQ: " + message.body) - SCHEDULE_PUSH_MSG = json.loads(message.body) + + m = json.loads(message.body) + command = m['event_type'] + logger.info("Handling command: " + command) + + if(command == 'update_schedule'): + SCHEDULE_PUSH_MSG = m['schedule'] # ACK the message to take it off the queue message.ack()