cc-1799 : Filesystem
running Notifier as a daemon, allows parallel processing of event queue at all times.
This commit is contained in:
parent
8b533bbd21
commit
4c8e6a04ac
4 changed files with 48 additions and 67 deletions
|
@ -22,56 +22,48 @@ def handleSigTERM(signum, frame):
|
|||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# configure logging
|
||||
try:
|
||||
logging.config.fileConfig("logging.cfg")
|
||||
except Exception, e:
|
||||
print 'Error configuring logging: ', e
|
||||
sys.exit()
|
||||
|
||||
# configure logging
|
||||
try:
|
||||
logging.config.fileConfig("logging.cfg")
|
||||
except Exception, e:
|
||||
print 'Error configuring logging: ', e
|
||||
sys.exit()
|
||||
logger = logging.getLogger()
|
||||
p = None
|
||||
|
||||
logger = logging.getLogger()
|
||||
p = None
|
||||
try:
|
||||
config = AirtimeMediaConfig()
|
||||
logger.info("Initializing event processor")
|
||||
pe = AirtimeProcessEvent(airtime_config=config)
|
||||
|
||||
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)
|
||||
notifier.coalesce_events()
|
||||
|
||||
notifier = AirtimeNotifier(pe.wm, pe, read_freq=1, timeout=1, airtime_config=config)
|
||||
notifier.coalesce_events()
|
||||
p = Process(target=notifier.process_file_events, args=(pe.file_events,))
|
||||
p.start()
|
||||
|
||||
p = Process(target=notifier.process_file_events, args=(pe.file_events,))
|
||||
p.daemon = True
|
||||
p.start()
|
||||
|
||||
signal.signal(signal.SIGTERM, handleSigTERM)
|
||||
signal.signal(signal.SIGTERM, handleSigTERM)
|
||||
|
||||
logger.info("Setting up monitor")
|
||||
response = None
|
||||
while response is None:
|
||||
response = notifier.api_client.setup_media_monitor()
|
||||
time.sleep(5)
|
||||
logger.info("Setting up monitor")
|
||||
response = None
|
||||
while response is None:
|
||||
response = notifier.api_client.setup_media_monitor()
|
||||
time.sleep(5)
|
||||
|
||||
storage_directory = response["stor"].encode('utf-8')
|
||||
logger.info("Storage Directory is: %s", storage_directory)
|
||||
config.storage_directory = storage_directory
|
||||
storage_directory = response["stor"].encode('utf-8')
|
||||
logger.info("Storage Directory is: %s", storage_directory)
|
||||
config.storage_directory = storage_directory
|
||||
|
||||
wdd = pe.watch_directory(storage_directory)
|
||||
logger.info("Added watch to %s", storage_directory)
|
||||
logger.info("wdd result %s", wdd[storage_directory])
|
||||
wdd = pe.watch_directory(storage_directory)
|
||||
logger.info("Added watch to %s", storage_directory)
|
||||
logger.info("wdd result %s", wdd[storage_directory])
|
||||
|
||||
#notifier.loop(callback=mm.notifier_loop_callback)
|
||||
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')
|
||||
|
||||
while True:
|
||||
if(notifier.check_events(1)):
|
||||
notifier.read_events()
|
||||
notifier.process_events()
|
||||
pe.notifier_loop_callback(notifier)
|
||||
except KeyboardInterrupt:
|
||||
notifier.stop()
|
||||
except Exception, e:
|
||||
notifier.stop()
|
||||
logger.error('Exception: %s', e)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
notifier.stop()
|
||||
except Exception, e:
|
||||
logger.error('Exception: %s', e)
|
||||
|
|
@ -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')
|
||||
|
@ -148,7 +146,7 @@ class AirtimeNotifier(Notifier):
|
|||
#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)
|
||||
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -8,7 +8,7 @@ from configobj import ConfigObj
|
|||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
PATH_INI_FILE = '/etc/airtime/media-monitor.cfg'
|
||||
|
||||
def remove_path(path):
|
||||
|
@ -18,7 +18,7 @@ def get_current_script_dir():
|
|||
current_script_dir = os.path.realpath(__file__)
|
||||
index = current_script_dir.rindex('/')
|
||||
return current_script_dir[0:index]
|
||||
|
||||
|
||||
try:
|
||||
# load config file
|
||||
try:
|
||||
|
@ -29,14 +29,15 @@ 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"
|
||||
remove_path(config["log_dir"])
|
||||
|
||||
|
||||
print "Removing symlinks"
|
||||
os.system("rm -f /usr/bin/airtime-media-monitor")
|
||||
|
||||
|
||||
print "Removing application files"
|
||||
remove_path(config["bin_dir"])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue