Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6edf65
commit e0bdda1
Showing
10 changed files
with
449 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Service for deploying jormungandr nodes in voting events.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,50 @@ | ||
class Jormungandr(object): | ||
import asyncio | ||
|
||
from .logs import getLogger | ||
|
||
# gets voting node logger | ||
logger = getLogger() | ||
|
||
|
||
class Jormungandr: | ||
"""Wrapper type for the jormungandr command-line.""" | ||
|
||
def __init__(self, jorm_exec: str): | ||
def __init__(self, jorm_exec: str) -> None: | ||
self.jorm_exec = jorm_exec | ||
|
||
# keeps on launching jormungandr until `stop_schedule()` is called | ||
async def run_jorm_node(self): | ||
jorm_task = asyncio.create_task(self.start_jormungandr()) | ||
try: | ||
logger.debug("jorm task starting") | ||
await jorm_task | ||
logger.debug("jorm task is finished") | ||
except Exception as e: | ||
logger.debug(f"jorm failed to start: {e}") | ||
|
||
async def start_jormungandr(self): | ||
try: | ||
await self.jormungandr_subprocess_exec() | ||
except Exception as e: | ||
f"jorm error: {e}" | ||
raise e | ||
|
||
async def jormungandr_subprocess_exec(self): | ||
try: | ||
proc = await asyncio.create_subprocess_exec( | ||
self.jorm_exec, # "--help", | ||
stdout=asyncio.subprocess.PIPE, | ||
stderr=asyncio.subprocess.PIPE, | ||
) | ||
stdout, stderr = await proc.communicate() | ||
|
||
if stdout: | ||
logger.info(f"[stdout]\n{stdout.decode()}") | ||
if stderr: | ||
logger.warning(f"[stderr]\n{stderr.decode()}") | ||
|
||
if proc.returncode != 0: | ||
raise Exception(f"jormungandr exited with non-zero status: {proc.returncode}") | ||
except Exception as e: | ||
logger.warning(f"jorm node error: {e}") | ||
raise e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.