mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-06 07:47:53 +10:00
refactor: move to_jsonl() methods to models
Move JSONL serialization from standalone functions to model methods to mirror the from_jsonl() pattern: - Add Binary.to_jsonl() method - Add Process.to_jsonl() method - Add ArchiveResult.to_jsonl() method - Add Snapshot.to_jsonl() method - Update write_index_jsonl() to use model methods - Update jsonl.py functions to be thin wrappers
This commit is contained in:
@@ -242,6 +242,22 @@ class Binary(ModelWithHealthStats):
|
||||
'is_valid': self.is_valid,
|
||||
}
|
||||
|
||||
def to_jsonl(self) -> dict:
|
||||
"""
|
||||
Convert Binary model instance to a JSONL record.
|
||||
"""
|
||||
return {
|
||||
'type': 'Binary',
|
||||
'id': str(self.id),
|
||||
'machine_id': str(self.machine_id),
|
||||
'name': self.name,
|
||||
'binprovider': self.binprovider,
|
||||
'abspath': self.abspath,
|
||||
'version': self.version,
|
||||
'sha256': self.sha256,
|
||||
'status': self.status,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def from_jsonl(record: dict, overrides: dict = None):
|
||||
"""
|
||||
@@ -606,6 +622,30 @@ class Process(ModelWithHealthStats):
|
||||
return self.archiveresult.hook_name
|
||||
return ''
|
||||
|
||||
def to_jsonl(self) -> dict:
|
||||
"""
|
||||
Convert Process model instance to a JSONL record.
|
||||
"""
|
||||
record = {
|
||||
'type': 'Process',
|
||||
'id': str(self.id),
|
||||
'machine_id': str(self.machine_id),
|
||||
'cmd': self.cmd,
|
||||
'pwd': self.pwd,
|
||||
'status': self.status,
|
||||
'exit_code': self.exit_code,
|
||||
'started_at': self.started_at.isoformat() if self.started_at else None,
|
||||
'ended_at': self.ended_at.isoformat() if self.ended_at else None,
|
||||
}
|
||||
# Include optional fields if set
|
||||
if self.binary_id:
|
||||
record['binary_id'] = str(self.binary_id)
|
||||
if self.pid:
|
||||
record['pid'] = self.pid
|
||||
if self.timeout:
|
||||
record['timeout'] = self.timeout
|
||||
return record
|
||||
|
||||
def update_and_requeue(self, **kwargs):
|
||||
"""
|
||||
Update process fields and requeue for worker state machine.
|
||||
|
||||
Reference in New Issue
Block a user