avoid db session while connecting to peer
This commit is contained in:
parent
0216c16c3d
commit
8c0f68e2d5
1 changed files with 42 additions and 31 deletions
29
oml/nodes.py
29
oml/nodes.py
|
@ -202,9 +202,15 @@ class Node(Thread):
|
||||||
def _send_response(self):
|
def _send_response(self):
|
||||||
with db.session():
|
with db.session():
|
||||||
u = user.models.User.get(self.user_id)
|
u = user.models.User.get(self.user_id)
|
||||||
if u and u.peered or u.queued:
|
send_response = u and u.peered or u.queued
|
||||||
|
if u:
|
||||||
|
user_pending = u.pending
|
||||||
|
user_peered = u.peered
|
||||||
|
user_queued = u.queued
|
||||||
if DEBUG_NODES:
|
if DEBUG_NODES:
|
||||||
logger.debug('go online peered=%s queued=%s %s (%s)', u.peered, u.queued, u.id, u.nickname)
|
logger.debug('go online peered=%s queued=%s %s (%s)', u.peered, u.queued, u.id, u.nickname)
|
||||||
|
|
||||||
|
if send_response:
|
||||||
try:
|
try:
|
||||||
self.online = self.can_connect()
|
self.online = self.can_connect()
|
||||||
except:
|
except:
|
||||||
|
@ -214,12 +220,12 @@ class Node(Thread):
|
||||||
if self.online:
|
if self.online:
|
||||||
if DEBUG_NODES:
|
if DEBUG_NODES:
|
||||||
logger.debug('connected to %s', self.url)
|
logger.debug('connected to %s', self.url)
|
||||||
if u.queued:
|
if user_queued:
|
||||||
if DEBUG_NODES:
|
if DEBUG_NODES:
|
||||||
logger.debug('queued peering event pending=%s peered=%s', u.pending, u.peered)
|
logger.debug('queued peering event pending=%s peered=%s', user_pending, user_peered)
|
||||||
if u.pending == 'sent':
|
if user_pending == 'sent':
|
||||||
self.peering('requestPeering')
|
self.peering('requestPeering')
|
||||||
elif u.pending == '' and u.peered:
|
elif user_pending == '' and user_peered:
|
||||||
self.peering('acceptPeering')
|
self.peering('acceptPeering')
|
||||||
else:
|
else:
|
||||||
#fixme, what about cancel/reject peering here?
|
#fixme, what about cancel/reject peering here?
|
||||||
|
@ -317,11 +323,14 @@ class Node(Thread):
|
||||||
def peering(self, action):
|
def peering(self, action):
|
||||||
with db.session():
|
with db.session():
|
||||||
u = user.models.User.get_or_create(self.user_id)
|
u = user.models.User.get_or_create(self.user_id)
|
||||||
|
user_info = u.info
|
||||||
if action in ('requestPeering', 'acceptPeering'):
|
if action in ('requestPeering', 'acceptPeering'):
|
||||||
r = self.request(action, settings.preferences['username'], u.info.get('message'))
|
r = self.request(action, settings.preferences['username'], user_info.get('message'))
|
||||||
else:
|
else:
|
||||||
r = self.request(action, u.info.get('message'))
|
r = self.request(action, user_info.get('message'))
|
||||||
if r != None:
|
if r is not None:
|
||||||
|
with db.session():
|
||||||
|
u = user.models.User.get(self.user_id)
|
||||||
u.queued = False
|
u.queued = False
|
||||||
if 'message' in u.info:
|
if 'message' in u.info:
|
||||||
del u.info['message']
|
del u.info['message']
|
||||||
|
@ -330,7 +339,9 @@ class Node(Thread):
|
||||||
logger.debug('peering failed? %s %s', action, r)
|
logger.debug('peering failed? %s %s', action, r)
|
||||||
if action in ('cancelPeering', 'rejectPeering', 'removePeering'):
|
if action in ('cancelPeering', 'rejectPeering', 'removePeering'):
|
||||||
self.online = False
|
self.online = False
|
||||||
trigger_event('peering.%s'%action.replace('Peering', ''), u.json())
|
with db.session():
|
||||||
|
u = user.models.User.get(self.user_id)
|
||||||
|
trigger_event('peering.%s' % action.replace('Peering', ''), u.json())
|
||||||
return True
|
return True
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
|
|
Loading…
Reference in a new issue