Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanups of AgentContext #719

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()}"}
]
Loading