本文整理汇总了Python中pillow_retry.models.PillowError.get_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python PillowError.get_or_create方法的具体用法?Python PillowError.get_or_create怎么用?Python PillowError.get_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pillow_retry.models.PillowError
的用法示例。
在下文中一共展示了PillowError.get_or_create方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_or_create
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def test_get_or_create(self):
message = 'abcd'
id = '12335'
error = create_error({'id': id}, message=message, attempts=2)
error.save()
get = PillowError.get_or_create({'id': id}, FakePillow())
self.assertEqual(get.total_attempts, 2)
self.assertEqual(get.current_attempt, 2)
self.assertTrue(message in error.error_traceback)
new = PillowError.get_or_create({'id': id}, FakePillow1())
self.assertIsNone(new.id)
self.assertEqual(new.current_attempt, 0)
示例2: test_get_or_create
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def test_get_or_create(self):
message = 'abcd'
id = '12335'
error = create_error(_change(id=id), message=message, attempts=2)
error.save()
get = PillowError.get_or_create(_change(id=id), FakePillow())
self.assertEqual(get.total_attempts, 2)
self.assertEqual(get.current_attempt, 2)
self.assertTrue(message in error.error_traceback)
another_pillow = make_fake_constructed_pillow('FakePillow1', '')
new = PillowError.get_or_create(_change(id=id), another_pillow)
self.assertIsNone(new.id)
self.assertEqual(new.current_attempt, 0)
示例3: test_empty_metadata
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def test_empty_metadata(self):
change = _change(id='123')
error = PillowError.get_or_create(change, GetDocPillow())
error.save()
process_pillow_retry(error)
error = PillowError.objects.get(pk=error.id)
self.assertEquals(error.total_attempts, 1)
示例4: test_null_meta_date
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def test_null_meta_date(self):
id = '12335'
meta = {
'domains': ['a' * 247, '123456789'],
'doc_type': 'something',
'date': None,
}
get = PillowError.get_or_create({'id': id}, FakePillow(), meta)
self.assertEqual(None, get.doc_date)
示例5: test_get_or_create_meta
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def test_get_or_create_meta(self):
id = '12335'
date = '2013-12-05T08:52:19Z'
meta = {
'domains': ['a' * 247, '123456789'],
'doc_type': 'something',
'date': date,
}
get = PillowError.get_or_create({'id': id}, FakePillow(), meta)
self.assertEqual(get.domains, 'a' * 247 + ',1234...')
self.assertEqual(get.doc_type, 'something')
self.assertEqual(get.doc_date, parse(date))
get.save()
示例6: _handle_pillow_error
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def _handle_pillow_error(self, change, exception):
try:
# This breaks the module boundary by using a show function defined in commcare-hq
# but it was decided that it wasn't worth the effort to maintain the separation.
meta = self.get_couch_db().show('domain/domain_date', change['id'])
except ResourceNotFound:
# Show function does not exist
meta = None
error = PillowError.get_or_create(change, self, change_meta=meta)
error.add_attempt(exception, sys.exc_info()[2])
error.save()
pillow_logging.exception(
"[%s] Error on change: %s, %s. Logged as: %s" % (
self.get_name(),
change['id'],
exception,
error.id
)
)
示例7: handle_pillow_error
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def handle_pillow_error(pillow, change, exception):
from couchdbkit import ResourceNotFound
from pillow_retry.models import PillowError
meta = None
if hasattr(pillow, 'get_couch_db'):
try:
meta = pillow.get_couch_db().show('domain_shows/domain_date', change['id'])
except ResourceNotFound:
pass
error = PillowError.get_or_create(change, pillow, change_meta=meta)
error.add_attempt(exception, sys.exc_info()[2])
error.save()
pillow_logging.exception(
"[%s] Error on change: %s, %s. Logged as: %s" % (
pillow.get_name(),
change['id'],
exception,
error.id
)
)
示例8: handle_pillow_error
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def handle_pillow_error(pillow, change, exception):
from pillow_retry.models import PillowError
pillow_logging.exception("[%s] Error on change: %s, %s" % (
pillow.get_name(),
change['id'],
exception,
))
datadog_counter('commcare.change_feed.changes.exceptions', tags=[
'pillow_name:{}'.format(pillow.get_name()),
])
# keep track of error attempt count
change.increment_attempt_count()
# always retry document missing errors, because the error is likely with couch
if pillow.retry_errors or isinstance(exception, DocumentMissingError):
error = PillowError.get_or_create(change, pillow)
error.add_attempt(exception, sys.exc_info()[2], change.metadata)
error.save()
示例9: create_error
# 需要导入模块: from pillow_retry.models import PillowError [as 别名]
# 或者: from pillow_retry.models.PillowError import get_or_create [as 别名]
def create_error(change, message='message', attempts=0, pillow=None, ex_class=None):
error = PillowError.get_or_create(change, pillow or FakePillow())
for n in range(0, attempts):
error.add_attempt(*get_ex_tb(message, ex_class=ex_class))
return error