Occaisonally persist unpersisted presence updates
parent
67f0c990f8
commit
21b977ccfe
|
@ -191,6 +191,13 @@ class PresenceHandler(object):
|
||||||
5000,
|
5000,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.clock.call_later(
|
||||||
|
60,
|
||||||
|
self.clock.looping_call,
|
||||||
|
self._persist_unpersisted_changes,
|
||||||
|
60 * 1000,
|
||||||
|
)
|
||||||
|
|
||||||
metrics.register_callback("wheel_timer_size", lambda: len(self.wheel_timer))
|
metrics.register_callback("wheel_timer_size", lambda: len(self.wheel_timer))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -216,6 +223,27 @@ class PresenceHandler(object):
|
||||||
])
|
])
|
||||||
logger.info("Finished _on_shutdown")
|
logger.info("Finished _on_shutdown")
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def _persist_unpersisted_changes(self):
|
||||||
|
"""We periodically persist the unpersisted changes, as otherwise they
|
||||||
|
may stack up and slow down shutdown times.
|
||||||
|
"""
|
||||||
|
logger.info(
|
||||||
|
"Performing _persist_unpersisted_changes. Persiting %d unpersisted changes",
|
||||||
|
len(self.user_to_current_state)
|
||||||
|
)
|
||||||
|
|
||||||
|
unpersisted = self.unpersisted_users_changes
|
||||||
|
self.unpersisted_users_changes = set()
|
||||||
|
|
||||||
|
if self.unpersisted_users_changes:
|
||||||
|
yield self.store.update_presence([
|
||||||
|
self.user_to_current_state[user_id]
|
||||||
|
for user_id in unpersisted
|
||||||
|
])
|
||||||
|
|
||||||
|
logger.info("Finished _persist_unpersisted_changes")
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _update_states(self, new_states):
|
def _update_states(self, new_states):
|
||||||
"""Updates presence of users. Sets the appropriate timeouts. Pokes
|
"""Updates presence of users. Sets the appropriate timeouts. Pokes
|
||||||
|
|
Loading…
Reference in New Issue