mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-20 19:10:45 +03:00
Update incremental processor to use new interfaces and track total_events
Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net>
This commit is contained in:
parent
a59da511ce
commit
1c9732d64b
1 changed files with 20 additions and 11 deletions
|
@ -85,27 +85,36 @@ class StatsHandler(StateDeltasHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _unsafe_process(self):
|
def _unsafe_process(self):
|
||||||
# If self.pos is None then means we haven't fetched it from DB
|
# If self.pos is None then means we haven't fetched it from DB
|
||||||
if self.pos is None:
|
if self.pos is None or None in self.pos.values():
|
||||||
self.pos = yield self.store.get_stats_stream_pos()
|
self.pos = yield self.store.get_stats_positions()
|
||||||
|
|
||||||
# If still None then the initial background update hasn't happened yet
|
# If still None then the initial background update hasn't started yet
|
||||||
if self.pos is None:
|
if self.pos is None or None in self.pos.values():
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
|
|
||||||
# Loop round handling deltas until we're up to date
|
# Loop round handling deltas until we're up to date
|
||||||
while True:
|
|
||||||
with Measure(self.clock, "stats_delta"):
|
with Measure(self.clock, "stats_delta"):
|
||||||
deltas = yield self.store.get_current_state_deltas(self.pos)
|
while True:
|
||||||
|
deltas = yield self.store.get_current_state_deltas(
|
||||||
|
self.pos["state_delta_stream_id"]
|
||||||
|
)
|
||||||
if not deltas:
|
if not deltas:
|
||||||
return
|
break
|
||||||
|
|
||||||
logger.info("Handling %d state deltas", len(deltas))
|
logger.info("Handling %d state deltas", len(deltas))
|
||||||
yield self._handle_deltas(deltas)
|
yield self._handle_deltas(deltas)
|
||||||
|
|
||||||
self.pos = deltas[-1]["stream_id"]
|
self.pos["state_delta_stream_id"] = deltas[-1]["stream_id"]
|
||||||
yield self.store.update_stats_stream_pos(self.pos)
|
|
||||||
|
|
||||||
event_processing_positions.labels("stats").set(self.pos)
|
event_processing_positions.labels("stats").set(
|
||||||
|
self.pos["state_delta_stream_id"]
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.pos is not None:
|
||||||
|
yield self.store.update_stats_positions(self.pos)
|
||||||
|
|
||||||
|
with Measure(self.clock, "stats_total_events"):
|
||||||
|
self.pos = yield self.store.incremental_update_total_events(self.pos)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _handle_deltas(self, deltas):
|
def _handle_deltas(self, deltas):
|
||||||
|
|
Loading…
Reference in a new issue