Files
ArchiveBox/archivebox/pkgs/abx-plugin-singlefile/abx_plugin_singlefile/actors.py
2024-11-03 00:41:11 -07:00

28 lines
1.0 KiB
Python

__package__ = 'abx_plugin_singlefile'
from typing import ClassVar
from django.db.models import QuerySet
from django.utils.functional import classproperty
from actors.actor import ActorType
from .models import SinglefileResult
class SinglefileActor(ActorType[SinglefileResult]):
CLAIM_ORDER: ClassVar[str] = 'created_at DESC'
CLAIM_WHERE: ClassVar[str] = 'status = "queued" AND extractor = "favicon"'
CLAIM_SET: ClassVar[str] = 'status = "started"'
@classproperty
def QUERYSET(cls) -> QuerySet:
return SinglefileResult.objects.filter(status='queued')
def tick(self, obj: SinglefileResult):
print(f'[grey53]{self}.tick({obj.abid or obj.id}, status={obj.status}) remaining:[/grey53]', self.get_queue().count())
updated = SinglefileResult.objects.filter(id=obj.id, status='started').update(status='success') == 1
if not updated:
raise Exception(f'Failed to update {obj.abid or obj.id}, interrupted by another actor writing to the same object')
obj.refresh_from_db()
obj.save()