build rate limiting: tests
This commit is contained in:
parent
57770493fa
commit
eb69abff8b
3 changed files with 31 additions and 7 deletions
|
@ -77,10 +77,14 @@ class WorkQueue(object):
|
|||
._available_jobs(now, name_match_query)
|
||||
.where(~(QueueItem.queue_name << running_query)))
|
||||
|
||||
def num_available_jobs(self, available_min_time, prefix):
|
||||
def num_available_jobs_between(self, available_min_time, available_max_time, prefix):
|
||||
"""
|
||||
Returns the number of available queue items with a given prefix between the two provided times.
|
||||
"""
|
||||
prefix = prefix.lstrip('/')
|
||||
available = self._available_jobs(datetime.utcnow(),
|
||||
self._name_match_query() + prefix)
|
||||
available = self._available_jobs(available_max_time,
|
||||
'/'.join([self._queue_name, prefix]) + '%')
|
||||
|
||||
return available.where(QueueItem.available_after >= available_min_time).count()
|
||||
|
||||
def _name_match_query(self):
|
||||
|
|
Reference in a new issue