本文整理汇总了Python中pillow_retry.models.PillowError类的典型用法代码示例。如果您正苦于以下问题:Python PillowError类的具体用法?Python PillowError怎么用?Python PillowError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PillowError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_items_to_be_processed
def test_get_items_to_be_processed(self):
p = PillowError(
date_created=datetime.datetime.utcnow() - datetime.timedelta(days=1),
date_next_attempt=datetime.datetime.utcnow() - datetime.timedelta(days=2),
date_last_attempt=datetime.datetime.utcnow() - datetime.timedelta(days=3),
)
p.save()
self.addCleanup(p.delete)
errors = list(PillowRetryEnqueuingOperation.get_items_to_be_processed(
datetime.datetime.utcnow()))
self.assertTrue(errors)
示例2: test_bulk_reset
def test_bulk_reset(self):
for i in range(0, 5):
error = create_error(_change(id=i), attempts=const.PILLOW_RETRY_QUEUE_MAX_PROCESSING_ATTEMPTS)
error.save()
errors = PillowError.get_errors_to_process(datetime.utcnow()).all()
self.assertEqual(len(errors), 0)
PillowError.bulk_reset_attempts(datetime.utcnow())
errors = PillowError.get_errors_to_process(datetime.utcnow()).all()
self.assertEqual(len(errors), 5)
示例3: test_bulk_reset_cutoff
def test_bulk_reset_cutoff(self):
for i in range(0, 3):
error = create_error({'id': i}, attempts=1)
if i >= 1:
error.total_attempts = PillowError.multi_attempts_cutoff() + 1
error.save()
errors = PillowError.get_errors_to_process(datetime.utcnow()).all()
self.assertEqual(len(errors), 0)
PillowError.bulk_reset_attempts(datetime.utcnow())
errors = PillowError.get_errors_to_process(datetime.utcnow()).all()
self.assertEqual(len(errors), 2)
示例4: test_get_or_create
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)
示例5: test_bulk_reset_cutoff
def test_bulk_reset_cutoff(self):
for i in range(0, 3):
error = create_error(_change(id=i), attempts=1)
if i >= 1:
error.total_attempts = const.PILLOW_RETRY_MULTI_ATTEMPTS_CUTOFF + 1
error.save()
errors = PillowError.get_errors_to_process(datetime.utcnow()).all()
self.assertEqual(len(errors), 0)
PillowError.bulk_reset_attempts(datetime.utcnow())
errors = PillowError.get_errors_to_process(datetime.utcnow()).all()
self.assertEqual(len(errors), 2)
示例6: test_get_or_create
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)
示例7: handle
def handle(self, *args, **options):
root_dir = settings.FILEPATH
git_snapshot = gitinfo.get_project_snapshot(root_dir, submodules=True)
git_snapshot['diff_url'] = options.get('url', None)
deploy = HqDeploy(
date=datetime.utcnow(),
user=options['user'],
environment=options['environment'],
code_snapshot=git_snapshot,
)
deploy.save()
# reset PillowTop errors in the hope that a fix has been deployed
rows_updated = PillowError.bulk_reset_attempts(datetime.utcnow())
if rows_updated:
print "\n---------------- Pillow Errors Reset ----------------\n" \
"{} pillow errors queued for retry\n".format(rows_updated)
if options['mail_admins']:
snapshot_table = render_to_string('hqadmin/partials/project_snapshot.html', dictionary={'snapshot': git_snapshot})
message = "Deployed by %s, cheers!" % options['user']
snapshot_body = "<html><head><title>Deploy Snapshot</title></head><body><h2>%s</h2>%s</body></html>" % (message, snapshot_table)
call_command('mail_admins', snapshot_body, **{'subject': 'Deploy successful', 'html': True})
示例8: test_get_errors_to_process_queued_update
def test_get_errors_to_process_queued_update(self):
date = datetime.utcnow()
error = create_error({'id': 1}, attempts=0)
error.date_next_attempt = date
error.save()
errors = PillowError.get_errors_to_process(
date,
).all()
self.assertEqual(len(errors), 1)
# check that calling update on the return value has the desired effect
errors.update(queued=True)
errors = PillowError.get_errors_to_process(
date,
).all()
self.assertEqual(len(errors), 0)
示例9: test_null_meta_date
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)
示例10: test_get_errors_to_process
def test_get_errors_to_process(self):
# Only re-process errors with
# current_attempt < const.PILLOW_RETRY_QUEUE_MAX_PROCESSING_ATTEMPTS
date = datetime.utcnow()
for i in range(0, 5):
error = create_error(_change(id=i), attempts=i+1)
error.date_next_attempt = date.replace(day=i+1)
error.save()
errors = PillowError.get_errors_to_process(
date.replace(day=1),
).all()
self.assertEqual(len(errors), 1)
errors = PillowError.get_errors_to_process(
date.replace(day=5),
).all()
self.assertEqual(len(errors), 3)
示例11: test_empty_metadata
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)
示例12: handle
def handle(self, *args, **options):
root_dir = settings.FILEPATH
git_snapshot = gitinfo.get_project_snapshot(root_dir, submodules=True)
compare_url = git_snapshot['diff_url'] = options.get('url', None)
deploy = HqDeploy(
date=datetime.utcnow(),
user=options['user'],
environment=options['environment'],
code_snapshot=git_snapshot,
)
deploy.save()
# reset PillowTop errors in the hope that a fix has been deployed
rows_updated = PillowError.bulk_reset_attempts(datetime.utcnow())
if rows_updated:
print "\n---------------- Pillow Errors Reset ----------------\n" \
"{} pillow errors queued for retry\n".format(rows_updated)
deploy_notification_text = (
"CommCareHQ has been successfully deployed to *{}* by *{}*. "
"Find the diff {{diff_link}}".format(
options['environment'],
options['user'],
)
)
if hasattr(settings, 'MIA_THE_DEPLOY_BOT_API'):
link = diff_link(STYLE_SLACK, compare_url)
requests.post(settings.MIA_THE_DEPLOY_BOT_API, data=json.dumps({
"username": "Igor the Iguana",
"text": deploy_notification_text.format(diff_link=link),
}))
if settings.DATADOG_API_KEY:
tags = ['environment:{}'.format(options['environment'])]
link = diff_link(STYLE_MARKDOWN, compare_url)
datadog_api.Event.create(
title="Deploy Success",
text=deploy_notification_text.format(diff_link=link),
tags=tags,
alert_type="success"
)
print "\n=============================================================\n" \
"Congratulations! Deploy Complete.\n\n" \
"Don't forget to keep an eye on the deploy dashboard to " \
"make sure everything is running smoothly.\n\n" \
"https://p.datadoghq.com/sb/5c4af2ac8-1f739e93ef" \
"\n=============================================================\n"
if options['mail_admins']:
message_body = get_deploy_email_message_body(
environment=options['environment'], user=options['user'],
compare_url=compare_url)
call_command('mail_admins', message_body, **{'subject': 'Deploy successful', 'html': True})
示例13: test_pillow_not_found
def test_pillow_not_found(self):
error = PillowError.objects.create(
doc_id='missing-pillow',
pillow='badmodule.NotARealPillow',
date_created=datetime.utcnow(),
date_last_attempt=datetime.utcnow()
)
# make sure this doesn't error
process_pillow_retry(error.id)
# and that its total_attempts was bumped above the threshold
self.assertTrue(PillowError.objects.get(pk=error.pk).total_attempts > PillowError.multi_attempts_cutoff())
示例14: test_get_or_create_meta
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()
示例15: handle
def handle(self, *args, **options):
root_dir = settings.FILEPATH
git_snapshot = gitinfo.get_project_snapshot(root_dir, submodules=True)
git_snapshot['diff_url'] = options.get('url', None)
deploy = HqDeploy(
date=datetime.utcnow(),
user=options['user'],
environment=options['environment'],
code_snapshot=git_snapshot,
)
deploy.save()
# reset PillowTop errors in the hope that a fix has been deployed
rows_updated = PillowError.bulk_reset_attempts(datetime.utcnow())
if rows_updated:
print "\n---------------- Pillow Errors Reset ----------------\n" \
"{} pillow errors queued for retry\n".format(rows_updated)
deploy_notification_text = (
"CommCareHQ has been successfully deployed to *{}* by *{}*. "
"Find the diff {{diff_link}}".format(
options['environment'],
options['user'],
)
)
if hasattr(settings, 'MIA_THE_DEPLOY_BOT_API'):
link = diff_link(STYLE_SLACK, git_snapshot['diff_url'])
requests.post(settings.MIA_THE_DEPLOY_BOT_API, data=json.dumps({
"channel": "#dev",
"username": "Mia the Deploy Bot",
"text": deploy_notification_text.format(diff_link=link),
"icon_emoji": ":see_no_evil:"
}))
if settings.DATADOG_API_KEY:
tags = ['environment:{}'.format(options['environment'])]
link = diff_link(STYLE_MARKDOWN, git_snapshot['diff_url'])
datadog_api.Event.create(
title="Deploy Success",
text=deploy_notification_text.format(diff_link=link),
tags=tags
)
if options['mail_admins']:
snapshot_table = render_to_string('hqadmin/partials/project_snapshot.html', dictionary={'snapshot': git_snapshot})
message = "Deployed by %s, cheers!" % options['user']
snapshot_body = "<html><head><title>Deploy Snapshot</title></head><body><h2>%s</h2>%s</body></html>" % (message, snapshot_table)
call_command('mail_admins', snapshot_body, **{'subject': 'Deploy successful', 'html': True})