cc-4105: modularized mm2.py. fixed little bug where proper last ran time wasn't being used

This commit is contained in:
Rudi Grinberg 2012-08-09 18:24:50 -04:00
parent 517730e012
commit 76bc290623
2 changed files with 73 additions and 65 deletions
python_apps/media-monitor2
media/monitor
mm2.py

View File

@ -3,7 +3,6 @@ from kombu.messaging import Exchange, Queue, Consumer
from kombu.connection import BrokerConnection from kombu.connection import BrokerConnection
import json import json
import os import os
import time
import copy import copy
import traceback import traceback
@ -105,7 +104,7 @@ class AirtimeMessageReceiver(Loggable):
if directory == None: directory = sdb.to_directory(directory_id) if directory == None: directory = sdb.to_directory(directory_id)
try: try:
bs = Bootstrapper( sdb, self.manager.watch_signal() ) bs = Bootstrapper( sdb, self.manager.watch_signal() )
bs.flush_watch( directory=directory, last_ran=time.time() ) bs.flush_watch( directory=directory, last_ran=self.cfg.last_ran() )
except Exception as e: except Exception as e:
self.logger.info( "Exception bootstrapping: (dir,id)=(%s,%s)" % self.logger.info( "Exception bootstrapping: (dir,id)=(%s,%s)" %
(directory, directory_id) ) (directory, directory_id) )

View File

@ -18,14 +18,14 @@ import media.monitor.pure as mmp
from api_clients import api_client as apc from api_clients import api_client as apc
base_path = u'/home/rudi/Airtime/python_apps/media-monitor2/tests'
global_config = os.path.join(base_path,u'live_client.cfg')
api_client_config = global_config
# MMConfig is a proxy around ConfigObj instances. it does not allow itself def main(global_config, api_client_config):
# users of MMConfig instances to modify any config options directly through the for cfg in [global_config, api_client_config]:
# dictionary. Users of this object muse use the correct methods designated for if not os.path.exists(cfg): raise NoConfigFile(cfg)
# modification # MMConfig is a proxy around ConfigObj instances. it does not allow
# itself users of MMConfig instances to modify any config options
# directly through the dictionary. Users of this object muse use the
# correct methods designated for modification
try: config = MMConfig(global_config) try: config = MMConfig(global_config)
except NoConfigFile as e: except NoConfigFile as e:
print("Cannot run mediamonitor2 without configuration file.") print("Cannot run mediamonitor2 without configuration file.")
@ -50,7 +50,8 @@ except FailedToObtainLocale as e:
'/etc/default/locale'") '/etc/default/locale'")
sys.exit(1) sys.exit(1)
except Exception as e: except Exception as e:
log.info("Failed to set the locale for unknown reason. Logging exception.") log.info("Failed to set the locale for unknown reason. \
Logging exception.")
log.info(str(e)) log.info(str(e))
watch_syncer = WatchSyncer(signal='watch', watch_syncer = WatchSyncer(signal='watch',
@ -90,10 +91,18 @@ bs = Bootstrapper( db=sdb, watch_signal='watch' )
ed = EventDrainer(airtime_notifier.connection, ed = EventDrainer(airtime_notifier.connection,
interval=float(config['rmq_event_wait'])) interval=float(config['rmq_event_wait']))
# Launch the toucher that updates the last time when the script was ran every n # Launch the toucher that updates the last time when the script was
# seconds. # ran every n seconds.
tt = ToucherThread(path=config['index_path'], tt = ToucherThread(path=config['index_path'],
interval=int(config['touch_interval'])) interval=int(config['touch_interval']))
pyi = manager.pyinotify() pyi = manager.pyinotify()
pyi.loop() pyi.loop()
if __name__ == '__main__':
# TODO : parse these from command line arguments
# TODO : add log config stuff
base_path = u'/home/rudi/Airtime/python_apps/media-monitor2/tests'
global_config = os.path.join(base_path, u'live_client.cfg')
api_client_config = global_config
main(global_config, api_client_config)