@@ -58,7 +58,7 @@ def __init__(
5858 self .deadline = None
5959
6060 def are_demands_satisfied (self ) -> bool :
61- return False
61+ return len ( self . missing_demands . all ) == 0
6262
6363 @singledispatchmethod
6464 def handle (self , event : Any ) -> RiskPeriodicCheckSagaStep :
@@ -68,37 +68,63 @@ def handle(self, event: Any) -> RiskPeriodicCheckSagaStep:
6868 def _handle_earnings_recalculated (
6969 self , event : EarningsRecalculated
7070 ) -> RiskPeriodicCheckSagaStep :
71- raise NotImplementedError
71+ self .earnings = event .earnings
72+ return RiskPeriodicCheckSagaStep .DO_NOTHING
7273
7374 @handle .register
7475 def _handle_project_allocations_demands_scheduled (
7576 self , event : ProjectAllocationsDemandsScheduled
7677 ) -> RiskPeriodicCheckSagaStep :
77- raise NotImplementedError
78+ self .missing_demands = event .missing_demands
79+ if self .are_demands_satisfied ():
80+ return RiskPeriodicCheckSagaStep .NOTIFY_ABOUT_DEMANDS_SATISFIED
81+ return RiskPeriodicCheckSagaStep .DO_NOTHING
7882
7983 @handle .register
8084 def _handle_project_allocations_scheduled (
8185 self , event : ProjectAllocationScheduled
8286 ) -> RiskPeriodicCheckSagaStep :
83- raise NotImplementedError
87+ self .deadline = event .from_to .to
88+ return RiskPeriodicCheckSagaStep .DO_NOTHING
8489
8590 @handle .register
8691 def _handle_resource_taken_over (
8792 self , event : ResourceTakenOver
8893 ) -> RiskPeriodicCheckSagaStep :
89- raise NotImplementedError
94+ if self .deadline is not None and event .occurred_at > self .deadline :
95+ return RiskPeriodicCheckSagaStep .DO_NOTHING
96+ return RiskPeriodicCheckSagaStep .NOTIFY_ABOUT_POSSIBLE_RISK
9097
9198 @handle .register
9299 def _handle_capability_released (
93100 self , event : CapabilityReleased
94101 ) -> RiskPeriodicCheckSagaStep :
95- raise NotImplementedError
102+ self .missing_demands = event .missing_demands
103+ return RiskPeriodicCheckSagaStep .DO_NOTHING
96104
97105 @handle .register
98106 def _handle_capabilities_allocated (
99107 self , event : CapabilitiesAllocated
100108 ) -> RiskPeriodicCheckSagaStep :
101- raise NotImplementedError
109+ self .missing_demands = event .missing_demands
110+ if self .are_demands_satisfied ():
111+ return RiskPeriodicCheckSagaStep .NOTIFY_ABOUT_DEMANDS_SATISFIED
112+ return RiskPeriodicCheckSagaStep .DO_NOTHING
102113
103114 def handle_weekly_check (self , when : datetime ) -> RiskPeriodicCheckSagaStep :
104- raise NotImplementedError
115+ if self .deadline is None or when > self .deadline :
116+ return RiskPeriodicCheckSagaStep .DO_NOTHING
117+
118+ if self .are_demands_satisfied ():
119+ return RiskPeriodicCheckSagaStep .DO_NOTHING
120+
121+ days_to_deadline = int ((self .deadline - when ).total_seconds () / 86400 )
122+ if days_to_deadline > self .UPCOMING_DEADLINE_AVAILABILITY_SEARCH :
123+ return RiskPeriodicCheckSagaStep .DO_NOTHING
124+ elif days_to_deadline > self .UPCOMING_DEADLINE_REPLACEMENT_SUGGESTION :
125+ return RiskPeriodicCheckSagaStep .FIND_AVAILABLE
126+
127+ if self .earnings >= self .RISK_THRESHOLD_VALUE :
128+ return RiskPeriodicCheckSagaStep .SUGGEST_REPLACEMENT
129+
130+ return RiskPeriodicCheckSagaStep .DO_NOTHING
0 commit comments