Skip to content

Commit

Permalink
Minor cleanups of AgentContext (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Nov 14, 2023
1 parent b16e58d commit a6a3b60
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AgentContext(ABC):
"""The Agent context interface"""

@abstractmethod
def get_persistent_state_directory(self):
def get_persistent_state_directory(self) -> Optional[str]:
"""Return the path of the agent disk. Return None if not configured."""
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class AgentContext(ABC):
"""The Agent context interface"""

@abstractmethod
def get_persistent_state_directory(self):
def get_persistent_state_directory(self) -> Optional[str]:
"""Return the path of the agent disk. Return None if not configured."""
return None
pass


class Agent(ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,8 @@ def __init__(self, configuration: dict, context: dict):
self.configuration = configuration
self.context = context

def get_persistent_state_directory(self) -> str:
dir = self.context.get("persistentStateDirectory", "")
if not dir:
return None
return dir
def get_persistent_state_directory(self) -> Optional[str]:
return self.context.get("persistentStateDirectory")


class AgentServer(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,27 @@ def process(self, record: Record) -> Future[List[RecordType]]:
return self.executor.submit(lambda r: [r], record)


class ProcessorInitOneParameter(Processor):
class ProcessorInitOneParameter:
def __init__(self):
self.myparam = None

def init(self, agent_config):
self.myparam = agent_config["my-param"]

def process(self, record: Record) -> List[RecordType]:
def process(self, _) -> List[RecordType]:
return [{"value": self.myparam}]


class ProcessorUseContext(Processor):
def __init__(self):
self.myparam = None
self.context = None

def init(self, agent_config, context: AgentContext):
self.myparam = agent_config["my-param"]
self.context = context

def process(self, record: Record) -> List[RecordType]:
return [
{
"value": "directory is "
+ str(self.context.get_persistent_state_directory())
}
{"value": f"directory is {self.context.get_persistent_state_directory()}"}
]

0 comments on commit a6a3b60

Please sign in to comment.