feat: address QA feedback and limit Checko collection
This commit is contained in:
@@ -117,6 +117,63 @@ class ParserBatchSequence(TimestampMixin, models.Model):
|
||||
return f"{self.source}: next batch {self.next_batch_id}"
|
||||
|
||||
|
||||
class CheckoCollectionAttempt(TimestampMixin, models.Model):
|
||||
"""Monthly Checko collection claim for one organization and source."""
|
||||
|
||||
class Source(models.TextChoices):
|
||||
ARBITRATION = "arbitration", _("Арбитражные дела")
|
||||
BANKRUPTCY = "bankruptcy", _("Банкротства")
|
||||
CONTRACTS = "contracts", _("Контракты")
|
||||
INSPECTIONS = "inspections", _("Проверки")
|
||||
|
||||
class Status(models.TextChoices):
|
||||
IN_PROGRESS = "in_progress", _("В процессе")
|
||||
SUCCESS = "success", _("Успешно")
|
||||
FAILED = "failed", _("Ошибка")
|
||||
|
||||
organization = models.ForeignKey(
|
||||
"organizations.Organization",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="checko_collection_attempts",
|
||||
verbose_name=_("организация"),
|
||||
)
|
||||
source = models.CharField(
|
||||
_("источник"),
|
||||
max_length=32,
|
||||
choices=Source.choices,
|
||||
)
|
||||
period_month = models.DateField(
|
||||
_("месяц сбора"),
|
||||
help_text=_("Первый день календарного месяца, за который занята попытка"),
|
||||
)
|
||||
status = models.CharField(
|
||||
_("статус"),
|
||||
max_length=20,
|
||||
choices=Status.choices,
|
||||
default=Status.IN_PROGRESS,
|
||||
)
|
||||
records_count = models.PositiveIntegerField(_("количество записей"), default=0)
|
||||
error_message = models.TextField(_("сообщение об ошибке"), blank=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "parsers_checko_collection_attempt"
|
||||
verbose_name = _("попытка сбора Checko")
|
||||
verbose_name_plural = _("попытки сбора Checko")
|
||||
ordering = ["-period_month", "source", "organization_id"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["organization", "source", "period_month"],
|
||||
name="unique_checko_collection_per_org_source_month",
|
||||
),
|
||||
]
|
||||
indexes = [
|
||||
models.Index(fields=["source", "period_month"]),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.organization_id}: {self.source} ({self.period_month:%Y-%m})"
|
||||
|
||||
|
||||
GENERIC_RECORD_SOURCE_CHOICES = [
|
||||
*ParserLoadLog.Source.choices,
|
||||
("hh", _("Вакансии HeadHunter")),
|
||||
|
||||
Reference in New Issue
Block a user