Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
james 2011-06-27 17:33:18 -04:00
commit ef7fe86af7
2 changed files with 23 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import logging
import logging.config
import sys
import os
import signal
from pyinotify import WatchManager, Notifier, ProcessEvent
from multiprocessing import Process, Lock, Queue as mpQueue
@ -13,6 +14,14 @@ from airtimefilemonitor.airtimenotifier import AirtimeNotifier
from airtimefilemonitor.airtimeprocessevent import AirtimeProcessEvent
from airtimefilemonitor.mediaconfig import AirtimeMediaConfig
def handleSigTERM(signum, frame):
logger.info("Main Process Shutdown, TERM signal caught. %d")
if p is not None:
p.terminate()
sys.exit(0)
if __name__ == '__main__':
# configure logging
@ -23,12 +32,11 @@ if __name__ == '__main__':
sys.exit()
logger = logging.getLogger()
p = None
try:
config = AirtimeMediaConfig()
logger.info("Initializing event processor")
pe = AirtimeProcessEvent(airtime_config=config)
notifier = AirtimeNotifier(pe.wm, pe, read_freq=1, timeout=1, airtime_config=config)
@ -38,6 +46,8 @@ if __name__ == '__main__':
p.daemon = True
p.start()
signal.signal(signal.SIGTERM, handleSigTERM)
logger.info("Setting up monitor")
response = None
while response is None:
@ -64,5 +74,4 @@ if __name__ == '__main__':
notifier.stop()
except Exception, e:
logger.error('Exception: %s', e)
finally:
p.terminate()

View File

@ -47,6 +47,12 @@ class AirtimeNotifier(Notifier):
return True
"""
Messages received from RabbitMQ are handled here. These messages
instruct media-monitor of events such as a new directory being watched,
file metadata has been changed, or any other changes to the config of
media-monitor via the web UI.
"""
def handle_message(self, body, message):
# ACK the message to take it off the queue
message.ack()
@ -139,11 +145,13 @@ class AirtimeNotifier(Notifier):
self.api_client.update_media_metadata(md, mode)
#this function is run in its own process, and continuously
#checks the queue for any new file events.
def process_file_events(self, queue):
while True:
event = queue.get()
self.logger.info("received event %s", event);
self.logger.info("received event %s", event)
self.update_airtime(event)
def walk_newly_watched_directory(self, directory):