Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3610 from matrix-org/rav/fix_looping_calls
Browse files Browse the repository at this point in the history
Fix some looping_call calls which were broken in #3604
  • Loading branch information
richvdh authored Jul 26, 2018
2 parents 1b4d73f + 03751a6 commit ef9d51b
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions changelog.d/3610.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add metrics to track resource usage by background processes
4 changes: 2 additions & 2 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def profiled(*args, **kargs):
stats_process = []

def start_phone_stats_home():
run_as_background_process("phone_stats_home", phone_stats_home)
return run_as_background_process("phone_stats_home", phone_stats_home)

@defer.inlineCallbacks
def phone_stats_home():
Expand Down Expand Up @@ -502,7 +502,7 @@ def performance_stats_init():
)

def generate_user_daily_visit_stats():
run_as_background_process(
return run_as_background_process(
"generate_user_daily_visits",
hs.get_datastore().generate_user_daily_visits,
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/groups/attestations.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def on_renew_attestation(self, group_id, user_id, content):
defer.returnValue({})

def _start_renew_attestations(self):
run_as_background_process("renew_attestations", self._renew_attestations)
return run_as_background_process("renew_attestations", self._renew_attestations)

@defer.inlineCallbacks
def _renew_attestations(self):
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _update_join_states(self, requester, target_user):
)

def _start_update_remote_profile_cache(self):
run_as_background_process(
return run_as_background_process(
"Update remote profile", self._update_remote_profile_cache,
)

Expand Down
10 changes: 8 additions & 2 deletions synapse/metrics/background_process_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,19 @@ def run_as_background_process(desc, func, *args, **kwargs):
This should be used to wrap processes which are fired off to run in the
background, instead of being associated with a particular request.
It returns a Deferred which completes when the function completes, but it doesn't
follow the synapse logcontext rules, which makes it appropriate for passing to
clock.looping_call and friends (or for firing-and-forgetting in the middle of a
normal synapse inlineCallbacks function).
Args:
desc (str): a description for this background process type
func: a function, which may return a Deferred
args: positional args for func
kwargs: keyword args for func
Returns: None
Returns: Deferred which returns the result of func, but note that it does not
follow the synapse logcontext rules.
"""
@defer.inlineCallbacks
def run():
Expand All @@ -176,4 +182,4 @@ def run():
_background_processes[desc].remove(proc)

with PreserveLoggingContext():
run()
return run()
2 changes: 1 addition & 1 deletion synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, hs):
)

def _start_update_recently_accessed(self):
run_as_background_process(
return run_as_background_process(
"update_recently_accessed_media", self._update_recently_accessed,
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/media/v1/preview_url_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def _download_url(self, url, user):
})

def _start_expire_url_cache_data(self):
run_as_background_process(
return run_as_background_process(
"expire_url_cache_data", self._expire_url_cache_data,
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/client_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def update():
to_update,
)

run_as_background_process(
return run_as_background_process(
"update_client_ips", update,
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def _prune_txn(txn):

logger.info("Pruned %d device list outbound pokes", txn.rowcount)

run_as_background_process(
return run_as_background_process(
"prune_old_outbound_device_pokes",
self.runInteraction,
"_prune_old_outbound_device_pokes",
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/event_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def _delete_old_forward_extrem_cache_txn(txn):
sql,
(self.stream_ordering_month_ago, self.stream_ordering_month_ago,)
)
run_as_background_process(
return run_as_background_process(
"delete_old_forward_extrem_cache",
self.runInteraction,
"_delete_old_forward_extrem_cache",
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def remove_push_actions_from_staging(self, event_id):
)

def _find_stream_orderings_for_times(self):
run_as_background_process(
return run_as_background_process(
"event_push_action_stream_orderings",
self.runInteraction,
"_find_stream_orderings_for_times",
Expand Down Expand Up @@ -790,7 +790,7 @@ def _remove_old_push_actions_before_txn(self, txn, room_id, user_id,
""", (room_id, user_id, stream_ordering))

def _start_rotate_notifs(self):
run_as_background_process("rotate_notifs", self._rotate_notifs)
return run_as_background_process("rotate_notifs", self._rotate_notifs)

@defer.inlineCallbacks
def _rotate_notifs(self):
Expand Down
4 changes: 3 additions & 1 deletion synapse/storage/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ def _get_destinations_needing_retry(self, txn):
return self.cursor_to_dict(txn)

def _start_cleanup_transactions(self):
run_as_background_process("cleanup_transactions", self._cleanup_transactions)
return run_as_background_process(
"cleanup_transactions", self._cleanup_transactions,
)

def _cleanup_transactions(self):
now = self._clock.time_msec()
Expand Down
2 changes: 1 addition & 1 deletion synapse/util/caches/expiringcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def start(self):
return

def f():
run_as_background_process(
return run_as_background_process(
"prune_cache_%s" % self._cache_name,
self._prune_cache,
)
Expand Down

0 comments on commit ef9d51b

Please sign in to comment.