From 5f1024bb7d42bb59db5f799afb85f01db3eef1be Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 30 Jul 2012 10:26:46 -0400 Subject: [PATCH] cc-4105: Tweaked config params. Fixed error checking. Fixed unicode stuff. Removed redundant php --- airtime_mvc/application/controllers/ApiController.php | 5 ++--- python_apps/media-monitor2/media/monitor/airtime.py | 1 - python_apps/media-monitor2/media/monitor/eventdrainer.py | 2 +- python_apps/media-monitor2/media/monitor/listeners.py | 2 ++ python_apps/media-monitor2/media/monitor/watchersyncer.py | 6 +++++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index cbe7521e6..128f65413 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -559,6 +559,8 @@ class ApiController extends Zend_Controller_Action // Valid requests must start with mdXXX where XXX represents at least 1 digit if( !preg_match('/^md\d+$/', $k) ) { continue; } $info_json = json_decode($raw_json, $assoc=true); + $recorded = $info_json["is_record"]; + unset( $info_json["is_record"] ); if( !array_key_exists('mode', $info_json) ) { // Log invalid requests Logging::log("Received bad request(key=$k), no 'mode' parameter. Bad request is:"); Logging::log( $info_json ); @@ -589,9 +591,6 @@ class ApiController extends Zend_Controller_Action // On recorded show requests we do some extra work here. Not sure what it actually is and it // was usually called from the python api client. Now we just call it straight from the controller to // save the http roundtrip - if( $info_json['is_record'] and !array_key_exists('error', $response) ) { - $this->uploadRecordedActionParam($info_json['showinstanceid'],$info_json['fileid'],$dry_run=$dry); - } } die( json_encode($responses) ); } diff --git a/python_apps/media-monitor2/media/monitor/airtime.py b/python_apps/media-monitor2/media/monitor/airtime.py index 671b27d00..ffd31fa00 100644 --- a/python_apps/media-monitor2/media/monitor/airtime.py +++ b/python_apps/media-monitor2/media/monitor/airtime.py @@ -44,7 +44,6 @@ class AirtimeNotifier(Loggable): except Exception as e: self.logger.info("Failed to initialize RabbitMQ consumer") self.logger.error(e) - raise def handle_message(self, body, message): """ diff --git a/python_apps/media-monitor2/media/monitor/eventdrainer.py b/python_apps/media-monitor2/media/monitor/eventdrainer.py index 54809034c..dbf0c5d89 100644 --- a/python_apps/media-monitor2/media/monitor/eventdrainer.py +++ b/python_apps/media-monitor2/media/monitor/eventdrainer.py @@ -5,7 +5,7 @@ from media.monitor.toucher import RepeatTimer class EventDrainer(Loggable): def __init__(self, connection, interval=1): def cb(): - try: connection.drain_events(timeout=0.1) + try: connection.drain_events(timeout=0.3) except socket.timeout: pass except Exception as e: self.logger.error("Error flushing events") diff --git a/python_apps/media-monitor2/media/monitor/listeners.py b/python_apps/media-monitor2/media/monitor/listeners.py index aee41c4f3..620dfd8fe 100644 --- a/python_apps/media-monitor2/media/monitor/listeners.py +++ b/python_apps/media-monitor2/media/monitor/listeners.py @@ -46,6 +46,7 @@ class FileMediator(object): def mediate_ignored(fn): def wrapped(self, event, *args,**kwargs): + event.pathname = unicode(event.pathname, "utf-8") if FileMediator.is_ignored(event.pathname): FileMediator.logger.info("Ignoring: '%s' (once)" % event.pathname) FileMediator.unignore(event.pathname) @@ -93,6 +94,7 @@ class StoreWatchListener(BaseListener, Loggable, pyinotify.ProcessEvent): @mediate_ignored @IncludeOnly(mmp.supported_extensions) def process_delete(self, event): + print(event) dispatcher.send(signal=self.signal, sender=self, event=DeleteFile(event)) def flush_events(self, path): diff --git a/python_apps/media-monitor2/media/monitor/watchersyncer.py b/python_apps/media-monitor2/media/monitor/watchersyncer.py index 7c4d15c8e..538b301ad 100644 --- a/python_apps/media-monitor2/media/monitor/watchersyncer.py +++ b/python_apps/media-monitor2/media/monitor/watchersyncer.py @@ -6,6 +6,7 @@ import copy from media.monitor.handler import ReportHandler from media.monitor.events import NewFile, DeleteFile from media.monitor.log import Loggable +from media.monitor.listeners import FileMediator from media.monitor.exceptions import BadSongFile from media.monitor.pure import LazyProperty @@ -17,6 +18,7 @@ class RequestSync(threading.Thread,Loggable): self.watcher = watcher self.requests = requests self.retries = 3 + self.request_wait = 0.3 @LazyProperty def apiclient(self): @@ -38,11 +40,13 @@ class RequestSync(threading.Thread,Loggable): try: make_req() except ValueError: self.logger.info("Api Controller is a piece of shit... will fix once I setup the damn debugger") - self.logger.info("Trying again...") + self.logger.info("Trying again after %f seconds" % self.request_wait) + time.sleep( self.request_wait ) else: self.logger.info("Request worked on the '%d' try" % (try_index + 1)) break else: self.logger.info("Failed to send request after '%d' tries..." % self.retries) + self.logger.info("Now ignoring: %d files" % len(FileMediator.ignored_set)) self.watcher.flag_done() class TimeoutWatcher(threading.Thread,Loggable):