@@ -44,6 +44,7 @@ class NotificationSettings(TypedDict, total=False):
4444class MonitorSettings (TypedDict , total = False ):
4545 capture_settings : CaptureSettings
4646 frequency : str
47+ never_expire : bool
4748 expire_at : Optional [Union [str , datetime , float ]]
4849 collection : Optional [str ]
4950 compare_settings : Optional [CompareSettings ]
@@ -176,6 +177,8 @@ def get_monitor_settings(self, monitor_uuid: str) -> MonitorSettings:
176177 to_return ['expire_at' ] = expire_at
177178 if collection := self .redis .get (f'{ monitor_uuid } :collection' ):
178179 to_return ['collection' ] = collection
180+ if never_expire := self .redis .exists (f'{ monitor_uuid } :ever_expire' ):
181+ to_return ['never_expire' ] = never_expire
179182 if compare_settings := self .get_compare_settings (monitor_uuid ):
180183 to_return ['compare_settings' ] = compare_settings
181184 if notification := self .redis .hgetall (f'{ monitor_uuid } :notification' ):
@@ -213,7 +216,9 @@ def monitor(self, *, capture_settings: CaptureSettings, frequency: str,
213216 def monitor (self , * , monitor_uuid : str , capture_settings : Optional [CaptureSettings ]= None ,
214217 frequency : Optional [str ]= None ,
215218 expire_at : Optional [Union [datetime , str , int , float ]]= None ,
216- collection : Optional [str ]= None , compare_settings : Optional [CompareSettings ]= None ,
219+ collection : Optional [str ]= None ,
220+ never_expire : bool = False ,
221+ compare_settings : Optional [CompareSettings ]= None ,
217222 notification : Optional [NotificationSettings ]= None ) -> str :
218223 """Update an existing monitoring with individual parameters"""
219224 ...
@@ -222,6 +227,7 @@ def monitor(self, *, capture_settings: Optional[CaptureSettings]=None,
222227 frequency : Optional [str ]= None ,
223228 expire_at : Optional [Union [datetime , str , int , float ]]= None ,
224229 collection : Optional [str ]= None ,
230+ never_expire : bool = False ,
225231 compare_settings : Optional [CompareSettings ]= None ,
226232 notification : Optional [NotificationSettings ]= None ,
227233 monitor_settings : Optional [MonitorSettings ]= None ,
@@ -241,6 +247,7 @@ def monitor(self, *, capture_settings: Optional[CaptureSettings]=None,
241247 frequency = monitor_settings .get ('frequency' )
242248 expire_at = monitor_settings .get ('expire_at' )
243249 collection = monitor_settings .get ('collection' )
250+ never_expire = monitor_settings .get ('never_expire' , False )
244251 compare_settings = monitor_settings .get ('compare_settings' )
245252 notification = monitor_settings .get ('notification' )
246253
@@ -257,6 +264,9 @@ def monitor(self, *, capture_settings: Optional[CaptureSettings]=None,
257264 if frequency :
258265 p .set (f'{ monitor_uuid } :frequency' , frequency .lower ())
259266
267+ if never_expire :
268+ p .set (f'{ monitor_uuid } :never_expire' , 1 )
269+
260270 if collection :
261271 p .set (f'{ monitor_uuid } :collection' , collection )
262272 p .sadd ('collections' , collection )
@@ -386,7 +396,9 @@ def update_monitoring_queue(self):
386396 nb_restarts = 1
387397 else :
388398 nb_restarts = int (_nb_restarts ) + 1
389- if self .redis .zcard (f'{ monitor_uuid } :captures' ) > self .max_captures * nb_restarts :
399+ # if the capture is marked as "never_expire" (admin only), skip that.
400+ if (not self .redis .exists (f'{ monitor_uuid } :never_expire' )
401+ and self .redis .zcard (f'{ monitor_uuid } :captures' ) > self .max_captures * nb_restarts ):
390402 # Force expire monitoring
391403 self .redis .smove ('monitored' , 'expired' , monitor_uuid )
392404 logger .info ('Maximum amount of captures reached, expire..' )
0 commit comments