當前位置: 首頁>>代碼示例>>Python>>正文


Python PillowError.get_or_create方法代碼示例

本文整理匯總了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)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:16,代碼來源:tests.py

示例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)
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:17,代碼來源:test_model.py

示例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)
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:11,代碼來源:test_model.py

示例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)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:11,代碼來源:tests.py

示例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()
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:15,代碼來源:tests.py

示例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
         )
     )
開發者ID:philipkaare,項目名稱:commcare-hq,代碼行數:21,代碼來源:listener.py

示例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
        )
    )
開發者ID:saketkanth,項目名稱:commcare-hq,代碼行數:23,代碼來源:interface.py

示例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()
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:23,代碼來源:interface.py

示例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
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:7,代碼來源:tests.py


注:本文中的pillow_retry.models.PillowError.get_or_create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。