pymongo connection error cause that subprocess will end

This commit is contained in:
iLLiCiTiT 2019-10-23 14:33:01 +02:00
parent b7c2954061
commit d1bfa2412e
2 changed files with 25 additions and 16 deletions

View file

@ -31,11 +31,14 @@ class ProcessEventHub(ftrack_api.event.hub.EventHub):
super(ProcessEventHub, self).__init__(*args, **kwargs)
def prepare_dbcon(self):
self.dbcon.install()
if not self.is_table_created:
self.dbcon.create_table(self.table_name, capped=False)
self.dbcon.active_table = self.table_name
self.is_table_created = True
try:
self.dbcon.install()
if not self.is_table_created:
self.dbcon.create_table(self.table_name, capped=False)
self.dbcon.active_table = self.table_name
self.is_table_created = True
except pymongo.errors.AutoReconnect:
sys.exit(0)
def wait(self, duration=None):
'''Wait for events and handle as they arrive.
@ -46,7 +49,6 @@ class ProcessEventHub(ftrack_api.event.hub.EventHub):
'''
started = time.time()
self.prepare_dbcon()
while True:
try:
@ -55,11 +57,14 @@ class ProcessEventHub(ftrack_api.event.hub.EventHub):
if not self.load_events():
time.sleep(0.5)
else:
self._handle(event)
self.dbcon.update_one(
{"id": event["id"]},
{"$set": {"pype_data.is_processed": True}}
)
try:
self._handle(event)
self.dbcon.update_one(
{"id": event["id"]},
{"$set": {"pype_data.is_processed": True}}
)
except pymongo.errors.AutoReconnect:
sys.exit(0)
# Additional special processing of events.
if event['topic'] == 'ftrack.meta.disconnected':
break
@ -78,7 +83,6 @@ class ProcessEventHub(ftrack_api.event.hub.EventHub):
}
try:
event = ftrack_api.event.base.Event(**new_event_data)
print(event)
except Exception:
self.logger.exception(L(
'Failed to convert payload into event: {0}',

View file

@ -23,9 +23,12 @@ table_name = "ftrack_events"
ignore_topics = []
def install_db():
dbcon.install()
dbcon.create_table(table_name, capped=False)
dbcon.active_table = table_name
try:
dbcon.install()
dbcon.create_table(table_name, capped=False)
dbcon.active_table = table_name
except pymongo.errors.AutoReconnect:
sys.exit(0)
def launch(event):
if event.get("topic") in ignore_topics:
@ -47,6 +50,9 @@ def launch(event):
except pymongo.errors.DuplicateKeyError:
log.debug("Event: {} already exists".format(event_id))
except pymongo.errors.AutoReconnect:
sys.exit(0)
except Exception as exc:
log.error(
"Event: {} failed to store".format(event_id),
@ -76,7 +82,6 @@ def main(args):
session = StorerSession(auto_connect_event_hub=True, sock=sock)
register(session)
server = FtrackServer("event")
log.info(os.environ["FTRACK_EVENTS_PATH"])
log.debug("Launched Ftrack Event storer")
server.run_server(session, load_files=False)