本文整理汇总了Python中celery.exceptions.TimeoutError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.TimeoutError方法的具体用法?Python exceptions.TimeoutError怎么用?Python exceptions.TimeoutError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.exceptions
的用法示例。
在下文中一共展示了exceptions.TimeoutError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: waitForConsolidatedField
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def waitForConsolidatedField(request):
success = False
try:
paper = Paper.objects.get(pk=int(request.GET["id"]))
except (KeyError, ValueError, Paper.DoesNotExist):
return {'success': success, 'message': 'Invalid paper id'}, 404
field = request.GET.get('field')
value = None
try:
paper.consolidate_metadata(wait=True)
except TimeoutError:
# Zotero instance is down / slow / failing, consolidation failed. Not
# a big deal.
pass
if field == 'abstract':
value = kill_html(paper.abstract)
success = len(paper.abstract) > 64
else:
return {'success': success, 'message': 'Invalid field'}, 401
return {'success': success, 'value': value}
示例2: sync_collection
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def sync_collection(request, slug):
"""
Sync collection - engine API.
:param slug: collection_slug identifier.
:return: JSON response with the sync result
{
"engines": [
{"<engine_name_1>": {"success": true}},
{"<engine_name_2>": {"success": false, "message": "Message of error description"}}
]
}
"""
try:
result = [v for obj, v in module_views.sync_collection(request, slug, api_request=True)]
except TimeoutError:
log.debug(f"The Collection sync task failed because of timeout error.")
return HttpResponseBadRequest(reason="Collection sync was failed, the reason is: TimeoutError")
log.debug(f"The result of the sync task is: {result}")
return JsonResponse(data={'engines': result})
示例3: results
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def results(self):
"""Fetch result from either the cache or the queue
Raises TimeoutError if results aren't ready by self.timeout
"""
if self.query == "":
return {}
result = cache.get(self.get_cache_key())
if result is None or settings.CELERY_TASK_ALWAYS_EAGER:
search_task = self.search_task()
result = {"task": search_task.id}
cache.set(self.get_cache_key(), result, settings.SEARCH_TIMEOUT)
elif "task" in result:
search_task = AsyncResult(result["task"])
else:
return result
try:
return search_task.get(self.timeout)
except exceptions.TimeoutError:
return result or {}
except Exception:
# some error in the search task, so return an empty dict
return {}
示例4: search_api
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def search_api(request):
try:
key = request.GET["token"]
except KeyError:
raise http.Http404
result = cache.get(key)
if result is not None and "task" in result:
search_task = AsyncResult(result["task"])
try:
search_task.get(TIMEOUT)
except exceptions.TimeoutError:
return http.HttpResponse(status=202) # 202: still waiting for task
except Exception:
return http.HttpResponseBadRequest() # 400: search task errored
return http.HttpResponse(status=201) # 201: search results ready
elif result is not None:
return http.HttpResponse(status=201) # 201: search results ready
else:
return http.HttpResponseBadRequest() # 400: no search is being performed
示例5: test_get_task_run
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_get_task_run(self, task_mock):
task_mock.return_value.id = "abc"
task_mock.return_value.get.side_effect = exceptions.TimeoutError
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(task_mock.call_count, 1)
self.assertEqual(task_mock.return_value.get.call_count, 1)
self.assertEqual(task_mock.call_args, ((), {"kwargs": {
"user_id": self.user.id,
"search_term": u"cheddär",
"before": None,
"after": None,
}}))
self.assertEqual(response.context["waiting"], True)
self.assertNotIn("has_next", response.context)
self.assertNotIn("has_previous", response.context)
self.assertNotIn("last", response.context)
self.assertNotIn("first", response.context)
示例6: test_get_with_before_param
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_get_with_before_param(self, task_mock):
task_mock.return_value.id = "abc"
task_mock.return_value.get.side_effect = exceptions.TimeoutError
response = self.client.get(self.url + "?before=blahblah")
self.assertEqual(response.status_code, 200)
self.assertEqual(task_mock.call_count, 1)
self.assertEqual(task_mock.return_value.get.call_count, 1)
self.assertEqual(task_mock.call_args, ((), {"kwargs": {
"user_id": self.user.id,
"search_term": u"cheddär",
"before": "blahblah",
"after": None,
}}))
self.assertEqual(response.context["waiting"], True)
self.assertNotIn("has_next", response.context)
self.assertNotIn("has_previous", response.context)
self.assertNotIn("last", response.context)
self.assertNotIn("first", response.context)
示例7: test_get_with_before_and_after_param
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_get_with_before_and_after_param(self, task_mock):
task_mock.return_value.id = "abc"
task_mock.return_value.get.side_effect = exceptions.TimeoutError
response = self.client.get(self.url + "?after=blahblah&before=bluhbluh")
self.assertEqual(response.status_code, 200)
self.assertEqual(task_mock.call_count, 1)
self.assertEqual(task_mock.return_value.get.call_count, 1)
self.assertEqual(task_mock.call_args, ((), {"kwargs": {
"user_id": self.user.id,
"search_term": u"cheddär",
"before": "bluhbluh",
"after": "blahblah",
}}))
self.assertEqual(response.context["waiting"], True)
self.assertNotIn("has_next", response.context)
self.assertNotIn("has_previous", response.context)
self.assertNotIn("last", response.context)
self.assertNotIn("first", response.context)
示例8: test_get_task_run
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_get_task_run(self, task_mock):
task_mock.return_value.id = "abc"
task_mock.return_value.get.side_effect = exceptions.TimeoutError
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(task_mock.call_count, 1)
self.assertEqual(task_mock.return_value.get.call_count, 1)
self.assertEqual(task_mock.call_args, ((), {"kwargs": {
"user_id": self.user.id,
"search_term": u"cheddär",
"inbox": str(self.inbox),
"before": None,
"after": None,
}}))
self.assertEqual(response.context["waiting"], True)
self.assertNotIn("has_next", response.context)
self.assertNotIn("has_previous", response.context)
self.assertNotIn("last", response.context)
self.assertNotIn("first", response.context)
示例9: test_get_with_before_param
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_get_with_before_param(self, task_mock):
task_mock.return_value.id = "abc"
task_mock.return_value.get.side_effect = exceptions.TimeoutError
response = self.client.get(self.url + "?before=blahblah")
self.assertEqual(response.status_code, 200)
self.assertEqual(task_mock.call_count, 1)
self.assertEqual(task_mock.return_value.get.call_count, 1)
self.assertEqual(task_mock.call_args, ((), {"kwargs": {
"user_id": self.user.id,
"search_term": u"cheddär",
"inbox": str(self.inbox),
"before": "blahblah",
"after": None,
}}))
self.assertEqual(response.context["waiting"], True)
self.assertNotIn("has_next", response.context)
self.assertNotIn("has_previous", response.context)
self.assertNotIn("last", response.context)
self.assertNotIn("first", response.context)
示例10: test_get_with_before_and_after_param
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_get_with_before_and_after_param(self, task_mock):
task_mock.return_value.id = "abc"
task_mock.return_value.get.side_effect = exceptions.TimeoutError
response = self.client.get(self.url + "?after=blahblah&before=bluhbluh")
self.assertEqual(response.status_code, 200)
self.assertEqual(task_mock.call_count, 1)
self.assertEqual(task_mock.return_value.get.call_count, 1)
self.assertEqual(task_mock.call_args, ((), {"kwargs": {
"user_id": self.user.id,
"search_term": u"cheddär",
"inbox": str(self.inbox),
"before": "bluhbluh",
"after": "blahblah",
}}))
self.assertEqual(response.context["waiting"], True)
self.assertNotIn("has_next", response.context)
self.assertNotIn("has_previous", response.context)
self.assertNotIn("last", response.context)
self.assertNotIn("first", response.context)
示例11: get_result
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def get_result(self, params):
cid = params['celery_id']
a1 = app.AsyncResult(cid)
# Note: There is no reasonable way to validate a celery task
# asyncresult id. See:
# https://github.com/celery/celery/issues/3596#issuecomment-262102185
# This means for ALL values of celery_id return either the
# value or None. Note also that you will only be able to get
# the result via this method once. All subsequent calls will
# return None.
try:
return a1.get(timeout=0.2)
except TimeoutError:
return None
示例12: mock_timeout
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def mock_timeout(slug):
if slug == 'col1':
raise TimeoutError
return []
示例13: test_sync_collection_timeout
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_sync_collection_timeout(self, mock_sync):
expected_msg = 'Collection sync was failed, the reason is: TimeoutError'
mock_sync.delay().collect.side_effect = TimeoutError
url = reverse('api:sync_collection', kwargs={'slug': self.collection1.slug})
response = self.client.get(url)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.reason_phrase, expected_msg)
示例14: test_search_running_and_timeout
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_search_running_and_timeout(self, result_mock):
result_mock.return_value.get.side_effect = exceptions.TimeoutError
cache.cache.set(self.key, {"task": "blahblahblah"})
response = self.client.head(self.url)
self.assertEqual(response.status_code, 202)
self.assertEqual(result_mock.call_count, 1)
self.assertEqual(result_mock.call_args, (("blahblahblah",), {}))
示例15: test_get_cached_result
# 需要导入模块: from celery import exceptions [as 别名]
# 或者: from celery.exceptions import TimeoutError [as 别名]
def test_get_cached_result(self, task_mock):
inbox = factories.InboxFactory(user=self.user)
task_mock.return_value.id = "abc"
task_mock.return_value.get.side_effect = exceptions.TimeoutError
cache.set(self.key, {
"results": [inbox.id],
"has_next": True,
"has_previous": False,
"first": "some-randomstring",
"last": "somerandom-string",
})
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(task_mock.call_count, 0)
self.assertEqual(response.context["has_next"], True)
self.assertEqual(response.context["last"], "somerandom-string")
self.assertEqual(response.context["has_previous"], False)
self.assertEqual(response.context["first"], "some-randomstring")
self.assertEqual(response.context["waiting"], False)
cache.set(self.key, {
"results": [],
"has_next": True,
"has_previous": False,
"first": "some-randomstring",
"last": "somerandom-string",
})
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(task_mock.call_count, 0)
self.assertEqual(response.context["waiting"], False)
self.assertNotIn("has_next", response.context)
self.assertNotIn("has_previous", response.context)
self.assertNotIn("first", response.context)
self.assertNotIn("last", response.context)