mirror of https://github.com/skygpu/skynet.git
Merge pull request #8 from guilledk/ipfs-reconnect
add ipfs reconnect before publishing if not connected to peerspull/14/head
commit
61ab42c118
|
@ -66,7 +66,7 @@ class SkynetDGPUDaemon:
|
||||||
|
|
||||||
resp = await self.conn.begin_work(rid)
|
resp = await self.conn.begin_work(rid)
|
||||||
if 'code' in resp:
|
if 'code' in resp:
|
||||||
logging.info(f'probably beign worked on already... skip.')
|
logging.info(f'probably being worked on already... skip.')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -211,6 +211,11 @@ class SkynetGPUConnector:
|
||||||
img = Image.open(io.BytesIO(raw_img))
|
img = Image.open(io.BytesIO(raw_img))
|
||||||
img.save(f'ipfs-docker-staging/image.png')
|
img.save(f'ipfs-docker-staging/image.png')
|
||||||
|
|
||||||
|
# check peer connections, reconnect to skynet gateway if not
|
||||||
|
peers = self.ipfs_node.check_connect()
|
||||||
|
if self.ipfs_url not in peers:
|
||||||
|
self.ipfs_node.connect(self.ipfs_url)
|
||||||
|
|
||||||
ipfs_hash = self.ipfs_node.add('image.png')
|
ipfs_hash = self.ipfs_node.add('image.png')
|
||||||
|
|
||||||
self.ipfs_node.pin(ipfs_hash)
|
self.ipfs_node.pin(ipfs_hash)
|
||||||
|
|
|
@ -21,6 +21,8 @@ class IPFSDocker:
|
||||||
def add(self, file: str) -> str:
|
def add(self, file: str) -> str:
|
||||||
ec, out = self._container.exec_run(
|
ec, out = self._container.exec_run(
|
||||||
['ipfs', 'add', '-w', f'/export/{file}', '-Q'])
|
['ipfs', 'add', '-w', f'/export/{file}', '-Q'])
|
||||||
|
if ec != 0:
|
||||||
|
logging.error(out)
|
||||||
assert ec == 0
|
assert ec == 0
|
||||||
|
|
||||||
return out.decode().rstrip()
|
return out.decode().rstrip()
|
||||||
|
@ -38,6 +40,15 @@ class IPFSDocker:
|
||||||
|
|
||||||
assert ec == 0
|
assert ec == 0
|
||||||
|
|
||||||
|
def check_connect(self):
|
||||||
|
ec, out = self._container.exec_run(
|
||||||
|
['ipfs', 'swarm', 'peers'])
|
||||||
|
if ec != 0:
|
||||||
|
logging.error(out)
|
||||||
|
assert ec == 0
|
||||||
|
|
||||||
|
return out.splitlines()
|
||||||
|
|
||||||
|
|
||||||
@cm
|
@cm
|
||||||
def open_ipfs_node(name='skynet-ipfs'):
|
def open_ipfs_node(name='skynet-ipfs'):
|
||||||
|
|
Loading…
Reference in New Issue