pull changes while offline

This commit is contained in:
j 2016-02-24 12:49:00 +05:30
parent 130a900bb0
commit ba4f311fe1

View file

@ -169,6 +169,8 @@ class Node(Thread):
def can_connect(self): def can_connect(self):
self.resolve() self.resolve()
url = self.url url = self.url
if not state.online and not self.local:
return False
try: try:
if url: if url:
headers = { headers = {
@ -233,6 +235,11 @@ class Node(Thread):
}) })
def pullChanges(self): def pullChanges(self):
if state.shutdown:
return
self.online = self.can_connect()
if not self.online or state.shutdown:
return
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)
if not u or not self.online or not u.peered: if not u or not self.online or not u.peered:
@ -476,6 +483,8 @@ class Nodes(Thread):
return return
self._pulling = True self._pulling = True
library.sync_db() library.sync_db()
if state.shutdown:
return
users = [] users = []
with db.session(): with db.session():
from user.models import User from user.models import User
@ -487,10 +496,7 @@ class Nodes(Thread):
break break
node = self._nodes.get(u['id']) node = self._nodes.get(u['id'])
if node: if node:
if not state.shutdown: node.pullChanges()
node.online = node.can_connect()
if not state.shutdown and node.online:
node.pullChanges()
self._pulling = False self._pulling = False
def run(self): def run(self):