22from workflows .context import Context
33from workflows import Workflow , step
44from workflows .events import Event , StartEvent , StopEvent
5- from enum import Enum
65from logging import getLogger
76
87logger = getLogger (__name__ )
98
10- class Operation (Enum ):
11- SUM = "sum"
12- SUBTRACT = "subtract"
13- MULTIPLY = "multiply"
14- DIVIDE = "divide"
15-
16- class CalculatorInput (StartEvent ):
9+ class SumInput (StartEvent ):
1710 a : int
1811 b : int
19- operation : Operation
2012
2113class ProgressEvent (Event ):
2214 step : str
@@ -26,17 +18,16 @@ class ProgressEvent(Event):
2618class CalculateRequestEvent (Event ):
2719 a : int
2820 b : int
29- operation : Operation
3021
3122class CalculateResponseEvent (Event ):
3223 result : int
3324
34- class CalculatorOutput (StopEvent ):
25+ class SumOutput (StopEvent ):
3526 results : int
3627
37- class CalculatorWorkflow (Workflow ):
28+ class SumWorkflow (Workflow ):
3829 @step
39- async def initialize (self , ctx : Context , ev : CalculatorInput ) -> CalculateRequestEvent :
30+ async def initialize (self , ctx : Context , ev : SumInput ) -> CalculateRequestEvent :
4031 logger .info ("Starting sum workflow" )
4132 ctx .write_event_to_stream (
4233 ProgressEvent (
@@ -46,7 +37,7 @@ async def initialize(self, ctx: Context, ev: CalculatorInput) -> CalculateReques
4637 )
4738 )
4839 await asyncio .sleep (1.0 )
49- return CalculateRequestEvent (a = ev .a , b = ev .b , operation = ev . operation )
40+ return CalculateRequestEvent (a = ev .a , b = ev .b )
5041
5142 @step
5243 async def sum (self , ctx : Context , ev : CalculateRequestEvent ) -> CalculateResponseEvent :
@@ -59,18 +50,11 @@ async def sum(self, ctx: Context, ev: CalculateRequestEvent) -> CalculateRespons
5950 message = "Calculating result"
6051 )
6152 )
62- if ev .operation == Operation .SUM :
63- result = ev .a + ev .b
64- elif ev .operation == Operation .SUBTRACT :
65- result = ev .a - ev .b
66- elif ev .operation == Operation .MULTIPLY :
67- result = ev .a * ev .b
68- elif ev .operation == Operation .DIVIDE :
69- result = ev .a / ev .b
53+ result = ev .a + ev .b
7054 return CalculateResponseEvent (result = result )
7155
7256 @step
73- async def finalize (self , ctx : Context , ev : CalculateResponseEvent ) -> CalculatorOutput :
57+ async def finalize (self , ctx : Context , ev : CalculateResponseEvent ) -> SumOutput :
7458 logger .info ("Finalizing result" )
7559 await asyncio .sleep (1.0 )
76- return CalculatorOutput (results = ev .result )
60+ return SumOutput (results = ev .result )
0 commit comments