cc-1799 : Filesystem

running Notifier as a daemon, allows parallel processing of event queue at all times.
This commit is contained in:
Naomi Aro 2011-06-28 11:39:54 +02:00
parent 8b533bbd21
commit 4c8e6a04ac
4 changed files with 48 additions and 67 deletions

View file

@ -22,8 +22,6 @@ def handleSigTERM(signum, frame):
sys.exit(0)
if __name__ == '__main__':
# configure logging
try:
logging.config.fileConfig("logging.cfg")
@ -43,7 +41,6 @@ if __name__ == '__main__':
notifier.coalesce_events()
p = Process(target=notifier.process_file_events, args=(pe.file_events,))
p.daemon = True
p.start()
signal.signal(signal.SIGTERM, handleSigTERM)
@ -62,16 +59,11 @@ if __name__ == '__main__':
logger.info("Added watch to %s", storage_directory)
logger.info("wdd result %s", wdd[storage_directory])
#notifier.loop(callback=mm.notifier_loop_callback)
while True:
if(notifier.check_events(1)):
notifier.read_events()
notifier.process_events()
pe.notifier_loop_callback(notifier)
notifier.loop(daemonize=True, callback=pe.notifier_loop_callback, pid_file='/var/run/airtime-notifier.pid', stdout='/var/log/airtime/media-monitor/media-monitor.log')
except KeyboardInterrupt:
notifier.stop()
except Exception, e:
notifier.stop()
logger.error('Exception: %s', e)

View file

@ -66,12 +66,10 @@ class AirtimeNotifier(Notifier):
elif m['event_type'] == "new_watch":
self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory'])
#start a new process to walk through this folder and add the files to Airtime.
p = Process(target=self.walk_newly_watched_directory, args=(m['directory'],))
p.start()
self.import_processes[m['directory']] = p
#add this new folder to our list of watched folders
self.watched_folders.append(m['directory'])
self.walk_newly_watched_directory(m['directory'])
mm = self.proc_fun()
mm.watch_directory(m['directory'])
elif m['event_type'] == "remove_watch":
watched_directory = m['directory'].encode('utf-8')
@ -163,5 +161,7 @@ class AirtimeNotifier(Notifier):
full_filepath = path+"/"+filename
if mm.is_audio_file(full_filepath):
self.update_airtime({'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False})
self.logger.info("importing %s", full_filepath)
event = {'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False}
mm.file_events.put(event)

View file

@ -37,11 +37,6 @@ class AirtimeProcessEvent(ProcessEvent):
self.wm = WatchManager()
self.md_manager = AirtimeMetadata()
schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True)
schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem")
connection = BrokerConnection(self.config.cfg["rabbitmq_host"], self.config.cfg["rabbitmq_user"], self.config.cfg["rabbitmq_password"], "/")
channel = connection.channel()
def watch_directory(self, directory):
return self.wm.add_watch(directory, self.mask, rec=True, auto_add=True)
@ -278,13 +273,6 @@ class AirtimeProcessEvent(ProcessEvent):
def notifier_loop_callback(self, notifier):
#put a watch on any fully imported watched directories.
for watched_directory in notifier.import_processes.keys():
process = notifier.import_processes[watched_directory]
if not process.is_alive():
self.watch_directory(watched_directory)
del notifier.import_processes[watched_directory]
#check for any events recieved from Airtime.
try:
notifier.connection.drain_events(timeout=0.1)

View file

@ -29,6 +29,7 @@ try:
os.system("/etc/init.d/airtime-media-monitor stop")
os.system("rm -f /etc/init.d/airtime-media-monitor")
os.system("rm -f /var/run/airtime-notifier.pid")
os.system("update-rc.d -f airtime-media-monitor remove >/dev/null 2>&1")
print "Removing log directories"