summary refs log tree commit diff
path: root/synapse/app/phone_stats_home.py
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/app/phone_stats_home.py')
-rw-r--r--synapse/app/phone_stats_home.py33
1 files changed, 11 insertions, 22 deletions
diff --git a/synapse/app/phone_stats_home.py b/synapse/app/phone_stats_home.py
index daed8ccfe9..8a69104a04 100644
--- a/synapse/app/phone_stats_home.py
+++ b/synapse/app/phone_stats_home.py
@@ -11,7 +11,6 @@
 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
-
 import logging
 import math
 import resource
@@ -19,7 +18,10 @@ import sys
 
 from prometheus_client import Gauge
 
-from synapse.metrics.background_process_metrics import run_as_background_process
+from synapse.metrics.background_process_metrics import (
+    run_as_background_process,
+    wrap_as_background_process,
+)
 
 logger = logging.getLogger("synapse.app.homeserver")
 
@@ -41,6 +43,7 @@ registered_reserved_users_mau_gauge = Gauge(
 )
 
 
+@wrap_as_background_process("phone_stats_home")
 async def phone_stats_home(hs, stats, stats_process=_stats_process):
     logger.info("Gathering stats for reporting")
     now = int(hs.get_clock().time())
@@ -143,20 +146,10 @@ def start_phone_stats_home(hs):
             (int(hs.get_clock().time()), resource.getrusage(resource.RUSAGE_SELF))
         )
 
-    def start_phone_stats_home():
-        return run_as_background_process(
-            "phone_stats_home", phone_stats_home, hs, stats
-        )
-
-    def generate_user_daily_visit_stats():
-        return run_as_background_process(
-            "generate_user_daily_visits", hs.get_datastore().generate_user_daily_visits
-        )
-
     # Rather than update on per session basis, batch up the requests.
     # If you increase the loop period, the accuracy of user_daily_visits
     # table will decrease
-    clock.looping_call(generate_user_daily_visit_stats, 5 * 60 * 1000)
+    clock.looping_call(hs.get_datastore().generate_user_daily_visits, 5 * 60 * 1000)
 
     # monthly active user limiting functionality
     def reap_monthly_active_users():
@@ -167,6 +160,7 @@ def start_phone_stats_home(hs):
     clock.looping_call(reap_monthly_active_users, 1000 * 60 * 60)
     reap_monthly_active_users()
 
+    @wrap_as_background_process("generate_monthly_active_users")
     async def generate_monthly_active_users():
         current_mau_count = 0
         current_mau_count_by_service = {}
@@ -186,19 +180,14 @@ def start_phone_stats_home(hs):
         registered_reserved_users_mau_gauge.set(float(len(reserved_users)))
         max_mau_gauge.set(float(hs.config.max_mau_value))
 
-    def start_generate_monthly_active_users():
-        return run_as_background_process(
-            "generate_monthly_active_users", generate_monthly_active_users
-        )
-
     if hs.config.limit_usage_by_mau or hs.config.mau_stats_only:
-        start_generate_monthly_active_users()
-        clock.looping_call(start_generate_monthly_active_users, 5 * 60 * 1000)
+        generate_monthly_active_users()
+        clock.looping_call(generate_monthly_active_users, 5 * 60 * 1000)
     # End of monthly active user settings
 
     if hs.config.report_stats:
         logger.info("Scheduling stats reporting for 3 hour intervals")
-        clock.looping_call(start_phone_stats_home, 3 * 60 * 60 * 1000)
+        clock.looping_call(phone_stats_home, 3 * 60 * 60 * 1000, hs, stats)
 
         # We need to defer this init for the cases that we daemonize
         # otherwise the process ID we get is that of the non-daemon process
@@ -206,4 +195,4 @@ def start_phone_stats_home(hs):
 
         # We wait 5 minutes to send the first set of stats as the server can
         # be quite busy the first few minutes
-        clock.call_later(5 * 60, start_phone_stats_home)
+        clock.call_later(5 * 60, phone_stats_home, hs, stats)