@@ -327,31 +327,39 @@ def update_status(self, status: StatusEnum):
327327 """Update the task status"""
328328 self .update (status = status )
329329
330- def increment_progress (self , amount : int , min_value_interval : int = None , min_time_interval : int = None ):
330+ def increment_progress (self , amount : int , value_step : int = None , rate_limit : int = None ):
331331 """Increment the task progress by adding the specified amount to the current value.
332332 If the task value is not set it will be set to `amount`.
333333
334334 Arguments:
335335 amount: The amount to increment the task value by.
336- min_value_interval: The minimum change in value required to trigger an update.
337- min_time_interval: The minimum interval between updates in seconds.
336+ value_step: The minimum change in value required to trigger an update.
337+ rate_limit: The minimum interval between updates in seconds.
338+
339+ If either `value_step` or `rate_limit` is set, the task will only be updated if the
340+ specified conditions are met. If both are set, the task will be updated if either
341+ condition is met.
338342 """
339343 value = self ._task .value
340344 value_norm = value if value is not UNSET and value is not None else 0
341345 new_amount = value_norm + amount
342- self .update_progress (new_amount , min_value_interval , min_time_interval )
346+ self .update_progress (new_amount , value_step , rate_limit )
343347
344- def update_progress (self , value : int , min_value_interval : int = None , min_time_interval : int = None ):
348+ def update_progress (self , value : int , value_step : int = None , rate_limit : int = None ):
345349 """Update task progress.
346350
347351 Arguments:
348352 value: The new value to set.
349- min_value_interval: The minimum change in value required to trigger an update.
350- min_time_interval: The minimum interval between updates in seconds.
353+ value_step: The minimum change in value required to trigger an update.
354+ rate_limit: The minimum interval between updates in seconds.
355+
356+ If either `value_step` or `rate_limit` is set, the task will only be updated if the
357+ specified conditions are met. If both are set, the task will be updated if either
358+ condition is met.
351359 """
352- skip_check = not (min_value_interval or min_time_interval )
353- time_check = min_time_interval and self ._check_update_time_interval (min_time_interval )
354- value_check = min_value_interval and self ._check_update_value_interval (value , min_value_interval )
360+ skip_check = not (value_step or rate_limit )
361+ time_check = rate_limit and self ._check_update_time_interval (rate_limit )
362+ value_check = value_step and self ._check_update_value_interval (value , value_step )
355363 if skip_check or time_check or value_check :
356364 self .update (value = value )
357365
@@ -408,15 +416,15 @@ def tag(self, tags: dict[str, str]):
408416 """Add tags to the task."""
409417 self .update (tags = tags )
410418
411- def ping (self , min_time_interval = None ):
419+ def ping (self , rate_limit = None ):
412420 """Update the task without changing any values. This can be used in conjunction
413421 with 'stale_timeout' to indicate that the task is still running.
414422
415423 Arguments:
416- min_time_interval : The minimum interval between pings in seconds. If set this will only
417- update the task if the last update was more than `min_time_interval ` seconds ago.
424+ rate_limit : The minimum interval between pings in seconds. If set this will only
425+ update the task if the last update was more than `rate_limit ` seconds ago.
418426 """
419- if self ._check_update_time_interval (min_time_interval ):
427+ if self ._check_update_time_interval (rate_limit ):
420428 self .update ()
421429
422430 @property
@@ -432,8 +440,8 @@ def safe_update(self, **kwargs):
432440 except Exception as e :
433441 log .warning ("Error updating task '%s': %s" , self ._task .id , e )
434442
435- def _check_update_time_interval (self , min_time_interval : int = None ):
436- if min_time_interval and self ._task .updated :
443+ def _check_update_time_interval (self , rate_limit : int = None ):
444+ if rate_limit and self ._task .updated :
437445 # tzinfo should always be set but for the sake of safety we check
438446 if self ._task .updated .tzinfo is None :
439447 tz = None
@@ -442,12 +450,12 @@ def _check_update_time_interval(self, min_time_interval: int = None):
442450 tz = datetime .timezone .utc
443451 now = datetime .datetime .now (tz )
444452 time_since = now - self ._task .updated
445- return time_since .total_seconds () >= min_time_interval
453+ return time_since .total_seconds () >= rate_limit
446454 return True
447455
448- def _check_update_value_interval (self , new_value , min_value_interval : int = None ):
449- if min_value_interval and self ._task .value :
450- return new_value - self ._task .value >= min_value_interval
456+ def _check_update_value_interval (self , new_value , value_step : int = None ):
457+ if value_step and self ._task .value :
458+ return new_value - self ._task .value >= value_step
451459 return True
452460
453461
0 commit comments