mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-16 16:14:28 -04:00

Some checks failed
Build Docker image / buildx (push) Has been cancelled
Build Homebrew package / build (push) Has been cancelled
Run linters / lint (push) Has been cancelled
Build Pip package / build (push) Has been cancelled
Run tests / python_tests (ubuntu-22.04, 3.11) (push) Has been cancelled
Run tests / docker_tests (push) Has been cancelled
Build Debian package / build (push) Has been cancelled
27 lines
1 KiB
Python
27 lines
1 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()
|