Skip to content

Commit fa94194

Browse files
committed
update command types to add Payload class
1 parent f811a61 commit fa94194

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

aikido_zen/background_process/commands/command.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,24 @@ class Command(ABC):
1717
def identifier(cls) -> str:
1818
pass
1919

20+
@classmethod
21+
@abstractmethod
22+
def returns_data(cls) -> bool:
23+
pass
24+
2025
@classmethod
2126
@abstractmethod
2227
def run(cls, context: CommandContext, request):
2328
pass
29+
30+
@classmethod
31+
@abstractmethod
32+
def generate(cls, *args, **kwargs):
33+
pass
34+
35+
36+
class Payload:
37+
def __init__(self, command: type[Command], request):
38+
self.identifier = command.identifier()
39+
self.returns_data = command.returns_data()
40+
self.request = request

aikido_zen/background_process/commands/put_event.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .command import Command, CommandContext
1+
from .command import Command, CommandContext, Payload
22

33

44
class PutEventReq:
@@ -13,6 +13,14 @@ class PutEventCommand(Command):
1313
def identifier(cls) -> str:
1414
return "put_event"
1515

16+
@classmethod
17+
def returns_data(cls) -> bool:
18+
return False
19+
1620
@classmethod
1721
def run(cls, context: CommandContext, request: PutEventReq):
1822
context.queue.put(request.event)
23+
24+
@classmethod
25+
def generate(cls, event) -> Payload:
26+
return Payload(cls, PutEventReq(event))

0 commit comments

Comments
 (0)