mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-28 05:34:14 -04:00
rename actors to workers
This commit is contained in:
parent
9b8cf7b4f0
commit
f5727c7da2
5 changed files with 115 additions and 120 deletions
|
@ -1,14 +1,13 @@
|
|||
__package__ = 'archivebox.crawls'
|
||||
|
||||
from typing import ClassVar
|
||||
from django.utils import timezone
|
||||
|
||||
from statemachine import State, StateMachine
|
||||
|
||||
from actors.actor import ActorType
|
||||
from crawls.models import Crawl
|
||||
|
||||
# State Machine Definitions
|
||||
#################################################
|
||||
|
||||
|
||||
class CrawlMachine(StateMachine, strict_states=True):
|
||||
"""State machine for managing Crawl lifecycle."""
|
||||
|
@ -22,9 +21,9 @@ class CrawlMachine(StateMachine, strict_states=True):
|
|||
|
||||
# Tick Event
|
||||
tick = (
|
||||
queued.to.itself(unless='can_start') |
|
||||
queued.to.itself(unless='can_start', internal=True) |
|
||||
queued.to(started, cond='can_start') |
|
||||
started.to.itself(unless='is_finished') |
|
||||
started.to.itself(unless='is_finished', internal=True) |
|
||||
started.to(sealed, cond='is_finished')
|
||||
)
|
||||
|
||||
|
@ -63,3 +62,18 @@ class CrawlMachine(StateMachine, strict_states=True):
|
|||
self.crawl.retry_at = None
|
||||
self.crawl.save()
|
||||
|
||||
|
||||
class CrawlWorker(ActorType[Crawl]):
|
||||
"""The Actor that manages the lifecycle of all Crawl objects"""
|
||||
|
||||
Model = Crawl
|
||||
StateMachineClass = CrawlMachine
|
||||
|
||||
ACTIVE_STATE: ClassVar[State] = CrawlMachine.started
|
||||
FINAL_STATES: ClassVar[list[State]] = CrawlMachine.final_states
|
||||
STATE_FIELD_NAME: ClassVar[str] = Crawl.state_field_name
|
||||
|
||||
MAX_CONCURRENT_ACTORS: ClassVar[int] = 3
|
||||
MAX_TICK_TIME: ClassVar[int] = 10
|
||||
CLAIM_FROM_TOP_N: ClassVar[int] = MAX_CONCURRENT_ACTORS * 10
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue