fix statemachine progression for Snapshot, Crawl, and ArchiveResult

This commit is contained in:
Nick Sweeting 2024-11-16 02:46:45 -08:00
parent 684a394cba
commit 227fd4e1c6
No known key found for this signature in database
3 changed files with 50 additions and 21 deletions

View file

@ -20,9 +20,9 @@ class CrawlMachine(StateMachine, strict_states=True):
# Tick Event
tick = (
queued.to.itself(unless='can_start', internal=True) |
queued.to.itself(unless='can_start') |
queued.to(started, cond='can_start') |
started.to.itself(unless='is_finished', internal=True) |
started.to.itself(unless='is_finished') |
started.to(sealed, cond='is_finished')
)
@ -34,15 +34,28 @@ class CrawlMachine(StateMachine, strict_states=True):
return self.crawl.seed and self.crawl.seed.uri
def is_finished(self) -> bool:
return not self.crawl.has_pending_archiveresults()
if not self.crawl.snapshot_set.exists():
return False
if self.crawl.pending_snapshots().exists():
return False
if self.crawl.pending_archiveresults().exists():
return False
return True
# def before_transition(self, event, state):
# print(f"Before '{event}', on the '{state.id}' state.")
# return "before_transition_return"
@started.enter
def on_started(self):
print(f'CrawlMachine[{self.crawl.ABID}].on_started(): crawl.create_root_snapshot() + crawl.bump_retry_at(+10s)')
self.crawl.create_root_snapshot()
self.crawl.bump_retry_at(seconds=10)
self.crawl.save()
@sealed.enter
def on_sealed(self):
print(f'CrawlMachine[{self.crawl.ABID}].on_sealed(): crawl.retry_at=None')
self.crawl.retry_at = None
self.crawl.save()