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

Commit

Permalink
Run MAU queries as background processes
Browse files Browse the repository at this point in the history
Fixes #3820
  • Loading branch information
richvdh committed Oct 20, 2018
1 parent 81d4f51 commit a6f421e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/4076.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly manage logcontexts during startup to fix some "Unexpected logging context" warnings
30 changes: 22 additions & 8 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,13 @@ def generate_user_daily_visit_stats():
clock.looping_call(generate_user_daily_visit_stats, 5 * 60 * 1000)

# monthly active user limiting functionality
clock.looping_call(
hs.get_datastore().reap_monthly_active_users, 1000 * 60 * 60
)
hs.get_datastore().reap_monthly_active_users()
def reap_monthly_active_users():
return run_as_background_process(
"reap_monthly_active_users",
hs.get_datastore().reap_monthly_active_users,
)
clock.looping_call(reap_monthly_active_users, 1000 * 60 * 60)
reap_monthly_active_users()

@defer.inlineCallbacks
def generate_monthly_active_users():
Expand All @@ -547,12 +550,23 @@ def generate_monthly_active_users():
registered_reserved_users_mau_gauge.set(float(reserved_count))
max_mau_gauge.set(float(hs.config.max_mau_value))

hs.get_datastore().initialise_reserved_users(
hs.config.mau_limits_reserved_threepids
def start_generate_monthly_active_users():
return run_as_background_process(
"generate_monthly_active_users",
generate_monthly_active_users,
)

# XXX is this really supposed to be a background process? it looks
# like it needs to complete before some of the other stuff runs.
run_as_background_process(
"initialise_reserved_users",
hs.get_datastore().initialise_reserved_users,
hs.config.mau_limits_reserved_threepids,
)
generate_monthly_active_users()

start_generate_monthly_active_users()
if hs.config.limit_usage_by_mau:
clock.looping_call(generate_monthly_active_users, 5 * 60 * 1000)
clock.looping_call(start_generate_monthly_active_users, 5 * 60 * 1000)
# End of monthly active user settings

if hs.config.report_stats:
Expand Down

0 comments on commit a6f421e

Please sign in to comment.