Close the gaps between the documented contract (API-STANDARD, TENANCY, ENTITLEMENTS) and the implementation, and remove committed build artifacts. Security: - verify + process inbound webhooks (HMAC/handler verify, size limit, timestamp tolerance, idempotency via InboundEvent.external_id) - real 2FA login flow (pre-auth challenge; tokens only after verify/recovery) - wire HybridPermission into security/audit views; add API-key rotate and users/<id>/permissions|roles endpoints - tenant-scoped throttling on by default; webhook replay protection - verify MercadoPago webhook signatures - login brute-force guard, configurable password policy, real ALTCHA PoW Correctness: - apply verified billing webhooks idempotently (subscription/entitlement/ invoice/PaymentTransaction); scheduled payment lifecycle jobs - capture audit update diffs automatically; add audit retention purge - working notification retries, per-channel rate limits, log retention - pluggable virus scanner, upload-size limit, pipeline toggle - feature rollout %/environment targeting; settings-driven registrations - workflow guards (instance cap, route depth, self-assignment, clone on re-entry) - wire every previously-dead INFRASYNTH_* setting; drop truly dead ones Delivery: - README + CHANGELOG; CI format check + coverage gate - keep test media out of the tree; untrack .coverage, __pycache__, egg-info, docs/ and invoice artifacts
53 lines
2 KiB
Python
53 lines
2 KiB
Python
from django.db import models
|
|
|
|
from infrasynth.tenancy.mixins import TenantOwnedModel
|
|
|
|
|
|
class ScheduledTask(TenantOwnedModel):
|
|
class ScheduleType(models.TextChoices):
|
|
CRON = "cron", "Cron"
|
|
INTERVAL = "interval", "Interval"
|
|
DATE = "date", "Date"
|
|
MANUAL = "manual", "Manual"
|
|
|
|
name = models.CharField(max_length=200)
|
|
task_path = models.CharField(max_length=500)
|
|
schedule_type = models.CharField(max_length=20, choices=ScheduleType.choices)
|
|
schedule_config = models.JSONField(default=dict)
|
|
args = models.JSONField(default=list)
|
|
kwargs = models.JSONField(default=dict)
|
|
is_active = models.BooleanField(default=True)
|
|
queue = models.CharField(max_length=100, blank=True)
|
|
priority = models.IntegerField(default=0)
|
|
|
|
class Meta:
|
|
db_table = "scheduler_task"
|
|
constraints = [models.UniqueConstraint(fields=["tenant", "name"], name="uniq_scheduled_task_name_per_tenant")]
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class TaskExecution(TenantOwnedModel):
|
|
class Status(models.TextChoices):
|
|
PENDING = "pending", "Pending"
|
|
RUNNING = "running", "Running"
|
|
SUCCESS = "success", "Success"
|
|
FAILURE = "failure", "Failure"
|
|
|
|
task = models.ForeignKey(ScheduledTask, on_delete=models.CASCADE, related_name="executions")
|
|
celery_task_id = models.CharField(max_length=255, blank=True)
|
|
status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING)
|
|
started_at = models.DateTimeField(null=True, blank=True)
|
|
completed_at = models.DateTimeField(null=True, blank=True)
|
|
result = models.TextField(blank=True)
|
|
error_traceback = models.TextField(blank=True)
|
|
worker_hostname = models.CharField(max_length=255, blank=True)
|
|
|
|
class Meta:
|
|
db_table = "scheduler_execution"
|
|
ordering = ["-started_at"]
|
|
indexes = [models.Index(fields=["tenant_id", "status"])]
|
|
|
|
def __str__(self):
|
|
return f"{self.task.name}#{self.pk}"
|