kopia lustrzana https://gitlab.com/marnanel/chapeau
sombrero gains "Failure" model to record HTTP failures
rodzic
71f5186d7f
commit
4eabf2dd1a
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 3.0.9 on 2020-10-18 22:18
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sombrero_sendpub', '0003_auto_20200730_2223'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Failure',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('url', models.URLField(max_length=256)),
|
||||
('status', models.IntegerField()),
|
||||
('found_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -86,3 +86,28 @@ class WebfingerUser(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return f'{self.username}@{self.hostname} -> {self.url}'
|
||||
|
||||
class Failure(models.Model):
|
||||
|
||||
url = models.URLField(
|
||||
max_length = 256,
|
||||
)
|
||||
|
||||
status = models.IntegerField()
|
||||
|
||||
found_at = models.DateTimeField(
|
||||
auto_now = True,
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
if self.status//100 == 2:
|
||||
raise ValueError(
|
||||
f"{self.url}: a result of {self.status} is "
|
||||
f"a success, not a failure!",
|
||||
)
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f'[{self.url} got {self.status}]'
|
||||
|
|
Ładowanie…
Reference in New Issue