Skip to content

Commit

Permalink
Make Portal communication optional
Browse files Browse the repository at this point in the history
  • Loading branch information
NaniteBased committed Sep 3, 2021
1 parent 3386c5c commit 38f5141
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Executor/executor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExecutorBase(Child):
def __init__(self, params: Dict, name: str, tempFolder: TemporaryDirectory = None):
if self.portal is None:
config = Config()
self.portal = PortalApi(config.Portal.Host, config.Portal.Port)
self.portal = PortalApi(config.Portal)

now = datetime.now(timezone.utc)
super().__init__(f"{name}{now.strftime('%y%m%d%H%M%S%f')}", tempFolder)
Expand Down
2 changes: 1 addition & 1 deletion Experiment/experiment_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, id: int, params: Dict):
if ExperimentRun.portal is None or ExperimentRun.grafana is None:
from Helper import DashboardGenerator # Delayed to avoid cyclic imports
config = Config()
ExperimentRun.portal = PortalApi(config.Portal.Host, config.Portal.Port)
ExperimentRun.portal = PortalApi(config.Portal)
ExperimentRun.grafana = DashboardGenerator(config.Grafana.Enabled, config.Grafana.Host,
config.Grafana.Port, config.Grafana.Bearer,
config.Grafana.ReportGenerator)
Expand Down
9 changes: 8 additions & 1 deletion Helper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ def Validation(self) -> List[Tuple['Level', str]]:

class Portal(restApi):
def __init__(self, data: Dict):
super().__init__(data, 'Portal', {})
defaults = {
'Enabled': (False, Level.WARNING)
}
super().__init__(data, 'Portal', defaults)

@property
def Enabled(self):
return self._keyOrDefault('Enabled')


class SliceManager(restApi):
Expand Down
1 change: 1 addition & 0 deletions Helper/default_config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Logging:
AppLevel: INFO
LogLevel: DEBUG
Portal:
Enabled: False
Host: '127.0.0.1'
Port: 5000
SliceManager:
Expand Down
12 changes: 7 additions & 5 deletions Interfaces/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
import json
from threading import Thread
from typing import Optional, Union
from Helper.config import Portal as PortalConfig


class PortalApi(RestClient):
def __init__(self, host, port):
super().__init__(host, port, '/api')
def __init__(self, config: PortalConfig):
self.Enabled = config.Enabled
super().__init__(config.Host, config.Port, '/api')

def UpdateExecutionData(self, executionId: int,
status: Optional[str] = None, dashboardUrl: Optional[str] = None,
percent: Optional[int] = None, message: Optional[str] = None):

Thread(target=self.updateAsync,
args=(executionId, status, dashboardUrl, percent, message)).start()
if self.Enabled:
Thread(target=self.updateAsync,
args=(executionId, status, dashboardUrl, percent, message)).start()

def updateAsync(self, executionId: int,
status: Optional[str], dashboardUrl: Optional[str],
Expand Down

0 comments on commit 38f5141

Please sign in to comment.