mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-07 08:58:11 +08:00
Adds infinite wait to task result functions
* the `wait` keyword now can take the value `-1` which will make the functions wait indefinitely for a result.
This commit is contained in:
+13
-13
@@ -106,7 +106,7 @@ def result(task_id, wait=0, cached=Conf.CACHED):
|
|||||||
r = Task.get_result(task_id)
|
r = Task.get_result(task_id)
|
||||||
if r:
|
if r:
|
||||||
return r
|
return r
|
||||||
if (time.time() - start) * 1000 >= wait:
|
if (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ def result_cached(task_id, wait=0, broker=None):
|
|||||||
r = broker.cache.get('{}:{}'.format(broker.list_key, task_id))
|
r = broker.cache.get('{}:{}'.format(broker.list_key, task_id))
|
||||||
if r:
|
if r:
|
||||||
return signing.SignedPackage.loads(r)['result']
|
return signing.SignedPackage.loads(r)['result']
|
||||||
if (time.time() - start) * 1000 >= wait:
|
if (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
@@ -142,14 +142,14 @@ def result_group(group_id, failures=False, wait=0, count=None, cached=Conf.CACHE
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
if count:
|
if count:
|
||||||
while True:
|
while True:
|
||||||
if count_group(group_id) == count or wait and (time.time() - start) * 1000 >= wait:
|
if count_group(group_id) == count or wait and (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
while True:
|
while True:
|
||||||
r = Task.get_result_group(group_id, failures)
|
r = Task.get_result_group(group_id, failures)
|
||||||
if r:
|
if r:
|
||||||
return r
|
return r
|
||||||
if (time.time() - start) * 1000 >= wait:
|
if (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ def result_group_cached(group_id, failures=False, wait=0, count=None, broker=Non
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
if count:
|
if count:
|
||||||
while True:
|
while True:
|
||||||
if count_group_cached(group_id) == count or wait and (time.time() - start) * 1000 >= wait:
|
if count_group_cached(group_id) == count or wait and (time.time() - start) * 1000 >= wait > 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
while True:
|
while True:
|
||||||
@@ -175,7 +175,7 @@ def result_group_cached(group_id, failures=False, wait=0, count=None, broker=Non
|
|||||||
if task['success'] or failures:
|
if task['success'] or failures:
|
||||||
result_list.append(task['result'])
|
result_list.append(task['result'])
|
||||||
return result_list
|
return result_list
|
||||||
if (time.time() - start) * 1000 >= wait:
|
if (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ def fetch(task_id, wait=0, cached=Conf.CACHED):
|
|||||||
t = Task.get_task(task_id)
|
t = Task.get_task(task_id)
|
||||||
if t:
|
if t:
|
||||||
return t
|
return t
|
||||||
if (time.time() - start) * 1000 >= wait:
|
if (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ def fetch_cached(task_id, wait=0, broker=None):
|
|||||||
result=task['result'],
|
result=task['result'],
|
||||||
success=task['success'])
|
success=task['success'])
|
||||||
return t
|
return t
|
||||||
if (time.time() - start) * 1000 >= wait:
|
if (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
@@ -245,14 +245,14 @@ def fetch_group(group_id, failures=True, wait=0, count=None, cached=Conf.CACHED)
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
if count:
|
if count:
|
||||||
while True:
|
while True:
|
||||||
if count_group(group_id) == count or wait and (time.time() - start) * 1000 >= wait:
|
if count_group(group_id) == count or wait and (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
while True:
|
while True:
|
||||||
r = Task.get_task_group(group_id, failures)
|
r = Task.get_task_group(group_id, failures)
|
||||||
if r:
|
if r:
|
||||||
return r
|
return r
|
||||||
if (time.time() - start) * 1000 >= wait:
|
if (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ def fetch_group_cached(group_id, failures=True, wait=0, count=None, broker=None)
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
if count:
|
if count:
|
||||||
while True:
|
while True:
|
||||||
if count_group_cached(group_id) == count or wait and (time.time() - start) * 1000 >= wait:
|
if count_group_cached(group_id) == count or wait and (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
while True:
|
while True:
|
||||||
@@ -289,7 +289,7 @@ def fetch_group_cached(group_id, failures=True, wait=0, count=None, broker=None)
|
|||||||
success=task['success'])
|
success=task['success'])
|
||||||
task_list.append(t)
|
task_list.append(t)
|
||||||
return task_list
|
return task_list
|
||||||
if (time.time() - start) * 1000 >= wait:
|
if (time.time() - start) * 1000 >= wait >= 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
@@ -472,7 +472,7 @@ class Iter(object):
|
|||||||
if self.started:
|
if self.started:
|
||||||
return result(self.id, wait=wait, cached=self.cached)
|
return result(self.id, wait=wait, cached=self.cached)
|
||||||
|
|
||||||
def fetch(self, wait=0):
|
def fetch(self, wait=0):
|
||||||
"""
|
"""
|
||||||
get the task result objects.
|
get the task result objects.
|
||||||
:param int wait: how many milliseconds to wait for a result
|
:param int wait: how many milliseconds to wait for a result
|
||||||
|
|||||||
Reference in New Issue
Block a user