diff options
author | Andrew Godwin | 2022-11-27 17:05:31 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-27 17:05:31 -0700 |
commit | 3b079526a2ea78b68555094ca498faea31022759 (patch) | |
tree | 28414e93aa7d412148fbcba6ecd6e2a0b09ecb5f /users/models/identity.py | |
parent | 2f443414a7e029f83292873257d2940b5a10cc64 (diff) | |
download | takahe-3b079526a2ea78b68555094ca498faea31022759.tar.gz takahe-3b079526a2ea78b68555094ca498faea31022759.tar.bz2 takahe-3b079526a2ea78b68555094ca498faea31022759.zip |
User fetching and inbox message cleaning
Diffstat (limited to 'users/models/identity.py')
-rw-r--r-- | users/models/identity.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/users/models/identity.py b/users/models/identity.py index 805755a..6957526 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -23,19 +23,31 @@ from users.models.system_actor import SystemActor class IdentityStates(StateGraph): - outdated = State(try_interval=3600) - updated = State() + """ + There are only two states in a cycle. + Identities sit in "updated" for up to system.identity_max_age, and then + go back to "outdated" for refetching. + """ + + outdated = State(try_interval=3600, force_initial=True) + updated = State(try_interval=86400, attempt_immediately=False) outdated.transitions_to(updated) + updated.transitions_to(outdated) @classmethod async def handle_outdated(cls, identity: "Identity"): # Local identities never need fetching if identity.local: - return "updated" + return cls.updated # Run the actor fetch and progress to updated if it succeeds if await identity.fetch_actor(): - return "updated" + return cls.updated + + @classmethod + async def handle_updated(cls, instance: "Identity"): + if instance.state_age > Config.system.identity_max_age: + return cls.outdated class Identity(StatorModel): |