mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-06 07:47:53 +10:00
actually working migration path from 0.7.2 and 0.8.6 + renames and test coverage
This commit is contained in:
@@ -8,7 +8,7 @@ from archivebox.machine.models import Machine, NetworkInterface, Binary, Process
|
||||
|
||||
|
||||
class MachineAdmin(ConfigEditorMixin, BaseModelAdmin):
|
||||
list_display = ('id', 'created_at', 'hostname', 'ips', 'os_platform', 'hw_in_docker', 'hw_in_vm', 'hw_manufacturer', 'hw_product', 'os_arch', 'os_family', 'os_release', 'hw_uuid', 'health')
|
||||
list_display = ('id', 'created_at', 'hostname', 'ips', 'os_platform', 'hw_in_docker', 'hw_in_vm', 'hw_manufacturer', 'hw_product', 'os_arch', 'os_family', 'os_release', 'hw_uuid', 'health_display')
|
||||
sort_fields = ('id', 'created_at', 'hostname', 'ips', 'os_platform', 'hw_in_docker', 'hw_in_vm', 'hw_manufacturer', 'hw_product', 'os_arch', 'os_family', 'os_release', 'hw_uuid')
|
||||
|
||||
readonly_fields = ('guid', 'created_at', 'modified_at', 'ips')
|
||||
@@ -52,9 +52,15 @@ class MachineAdmin(ConfigEditorMixin, BaseModelAdmin):
|
||||
machine.id, ', '.join(machine.networkinterface_set.values_list('ip_public', flat=True)),
|
||||
)
|
||||
|
||||
@admin.display(description='Health', ordering='health')
|
||||
def health_display(self, obj):
|
||||
h = obj.health
|
||||
color = 'green' if h >= 80 else 'orange' if h >= 50 else 'red'
|
||||
return format_html('<span style="color: {};">{}</span>', color, h)
|
||||
|
||||
|
||||
class NetworkInterfaceAdmin(BaseModelAdmin):
|
||||
list_display = ('id', 'created_at', 'machine_info', 'ip_public', 'dns_server', 'isp', 'country', 'region', 'city', 'iface', 'ip_local', 'mac_address', 'health')
|
||||
list_display = ('id', 'created_at', 'machine_info', 'ip_public', 'dns_server', 'isp', 'country', 'region', 'city', 'iface', 'ip_local', 'mac_address', 'health_display')
|
||||
sort_fields = ('id', 'created_at', 'machine_info', 'ip_public', 'dns_server', 'isp', 'country', 'region', 'city', 'iface', 'ip_local', 'mac_address')
|
||||
search_fields = ('id', 'machine__id', 'iface', 'ip_public', 'ip_local', 'mac_address', 'dns_server', 'hostname', 'isp', 'city', 'region', 'country')
|
||||
|
||||
@@ -95,9 +101,15 @@ class NetworkInterfaceAdmin(BaseModelAdmin):
|
||||
iface.machine.id, str(iface.machine.id)[:8], iface.machine.hostname,
|
||||
)
|
||||
|
||||
@admin.display(description='Health', ordering='health')
|
||||
def health_display(self, obj):
|
||||
h = obj.health
|
||||
color = 'green' if h >= 80 else 'orange' if h >= 50 else 'red'
|
||||
return format_html('<span style="color: {};">{}</span>', color, h)
|
||||
|
||||
|
||||
class BinaryAdmin(BaseModelAdmin):
|
||||
list_display = ('id', 'created_at', 'machine_info', 'name', 'binprovider', 'version', 'abspath', 'sha256', 'status', 'health')
|
||||
list_display = ('id', 'created_at', 'machine_info', 'name', 'binprovider', 'version', 'abspath', 'sha256', 'status', 'health_display')
|
||||
sort_fields = ('id', 'created_at', 'machine_info', 'name', 'binprovider', 'version', 'abspath', 'sha256', 'status')
|
||||
search_fields = ('id', 'machine__id', 'name', 'binprovider', 'version', 'abspath', 'sha256')
|
||||
|
||||
@@ -142,6 +154,12 @@ class BinaryAdmin(BaseModelAdmin):
|
||||
binary.machine.id, str(binary.machine.id)[:8], binary.machine.hostname,
|
||||
)
|
||||
|
||||
@admin.display(description='Health', ordering='health')
|
||||
def health_display(self, obj):
|
||||
h = obj.health
|
||||
color = 'green' if h >= 80 else 'orange' if h >= 50 else 'red'
|
||||
return format_html('<span style="color: {};">{}</span>', color, h)
|
||||
|
||||
|
||||
class ProcessAdmin(BaseModelAdmin):
|
||||
list_display = ('id', 'created_at', 'machine_info', 'archiveresult_link', 'cmd_str', 'status', 'exit_code', 'pid', 'binary_info')
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 6.0 on 2026-01-01 22:55
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('machine', '0002_process'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='process',
|
||||
name='parent',
|
||||
field=models.ForeignKey(blank=True, help_text='Parent process that spawned this process', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='machine.process'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='process',
|
||||
name='process_type',
|
||||
field=models.CharField(choices=[('supervisord', 'Supervisord'), ('orchestrator', 'Orchestrator'), ('worker', 'Worker'), ('cli', 'CLI'), ('binary', 'Binary')], db_index=True, default='cli', help_text='Type of process (cli, worker, orchestrator, binary, supervisord)', max_length=16),
|
||||
),
|
||||
]
|
||||
@@ -153,8 +153,8 @@ class NetworkInterface(ModelWithHealthStats):
|
||||
city = models.CharField(max_length=63, default=None, null=False)
|
||||
region = models.CharField(max_length=63, default=None, null=False)
|
||||
country = models.CharField(max_length=63, default=None, null=False)
|
||||
num_uses_failed = models.PositiveIntegerField(default=0)
|
||||
num_uses_succeeded = models.PositiveIntegerField(default=0)
|
||||
# num_uses_failed = models.PositiveIntegerField(default=0) # from ModelWithHealthStats
|
||||
# num_uses_succeeded = models.PositiveIntegerField(default=0) # from ModelWithHealthStats
|
||||
|
||||
objects: NetworkInterfaceManager = NetworkInterfaceManager()
|
||||
|
||||
@@ -588,6 +588,13 @@ class Process(models.Model):
|
||||
RUNNING = 'running', 'Running'
|
||||
EXITED = 'exited', 'Exited'
|
||||
|
||||
class TypeChoices(models.TextChoices):
|
||||
SUPERVISORD = 'supervisord', 'Supervisord'
|
||||
ORCHESTRATOR = 'orchestrator', 'Orchestrator'
|
||||
WORKER = 'worker', 'Worker'
|
||||
CLI = 'cli', 'CLI'
|
||||
BINARY = 'binary', 'Binary'
|
||||
|
||||
# Primary fields
|
||||
id = models.UUIDField(primary_key=True, default=uuid7, editable=False, unique=True)
|
||||
created_at = models.DateTimeField(default=timezone.now, db_index=True)
|
||||
@@ -602,6 +609,24 @@ class Process(models.Model):
|
||||
help_text='Machine where this process executed'
|
||||
)
|
||||
|
||||
# Parent process (optional)
|
||||
parent = models.ForeignKey(
|
||||
'self',
|
||||
on_delete=models.SET_NULL,
|
||||
null=True, blank=True,
|
||||
related_name='children',
|
||||
help_text='Parent process that spawned this process'
|
||||
)
|
||||
|
||||
# Process type (cli, worker, orchestrator, binary, supervisord)
|
||||
process_type = models.CharField(
|
||||
max_length=16,
|
||||
choices=TypeChoices.choices,
|
||||
default=TypeChoices.CLI,
|
||||
db_index=True,
|
||||
help_text='Type of process (cli, worker, orchestrator, binary, supervisord)'
|
||||
)
|
||||
|
||||
# Execution metadata
|
||||
pwd = models.CharField(max_length=512, default='', null=False, blank=True,
|
||||
help_text='Working directory for process execution')
|
||||
|
||||
Reference in New Issue
Block a user