2525from peterbecom .base .xcache_analyzer import get_x_cache
2626
2727
28+ def get_full_path (func ):
29+ return f"{ func .__module__ } .{ func .__qualname__ } "
30+
31+
32+ def log_task_run (func ):
33+ @functools .wraps (func )
34+ def wrapper (* args , ** kwargs ):
35+ t0 = time .time ()
36+ failed = False
37+ try :
38+ func (* args , ** kwargs )
39+ except Exception :
40+ failed = True
41+ finally :
42+ t1 = time .time ()
43+ if t1 - t0 < 1 :
44+ took = f"{ (t1 - t0 ) * 1000 :.1f} ms"
45+ else :
46+ took = f"{ (t1 - t0 ):.2f} s"
47+ print (
48+ f"(Crontab Task) { func .__module__ } .{ func .__qualname__ } " ,
49+ f"{ 'Failed!' if failed else 'Worked.' } " ,
50+ f"Took { took } . ({ timezone .now ()} )" ,
51+ )
52+
53+ return wrapper
54+
55+
2856def measure_post_process (func ):
2957 @functools .wraps (func )
3058 def inner (filepath , url , * args , ** kwargs ):
@@ -54,6 +82,7 @@ def inner(filepath, url, *args, **kwargs):
5482
5583
5684@periodic_task (crontab (minute = "*" ))
85+ @log_task_run
5786def run_purge_cdn_urls ():
5887 CDNPurgeURL .purge_old ()
5988 for i in range (3 ):
@@ -108,6 +137,7 @@ def post_process_after_cdn_purge(url):
108137
109138
110139@periodic_task (crontab (hour = "*" , minute = "3" ))
140+ @log_task_run
111141def purge_old_cdnpurgeurls ():
112142 old = timezone .now () - datetime .timedelta (days = 30 )
113143 ancient = CDNPurgeURL .objects .filter (created__lt = old )
@@ -116,6 +146,7 @@ def purge_old_cdnpurgeurls():
116146
117147
118148@periodic_task (crontab (hour = "*" , minute = "2" ))
149+ @log_task_run
119150def purge_old_postprocessings ():
120151 old = timezone .now () - datetime .timedelta (days = 30 )
121152 ancient = PostProcessing .objects .filter (created__lt = old )
@@ -133,6 +164,7 @@ def purge_old_postprocessings():
133164
134165
135166@periodic_task (crontab (minute = "*" ))
167+ @log_task_run
136168def health_check_to_disk ():
137169 health_file = Path ("/tmp/huey_health.json" )
138170 try :
@@ -159,30 +191,26 @@ def health_check_to_disk():
159191
160192
161193@periodic_task (crontab (minute = "2" ))
194+ @log_task_run
162195def create_analytics_geo_events_backfill ():
163- print (
164- "(Debugging Cron) Executing create_analytics_geo_events_backfill" ,
165- timezone .now (),
166- )
167196 create_analytics_geo_events (max = 1000 )
168197
169198
170199@periodic_task (crontab (minute = "3" ))
200+ @log_task_run
171201def create_analytics_referrer_events_backfill ():
172- print (
173- "(Debugging Cron) Executing create_analytics_referrer_events_backfill" ,
174- timezone .now (),
175- )
176202 create_analytics_referrer_events (max = 1000 )
177203
178204
179205@periodic_task (crontab (hour = "1" , minute = "2" ))
206+ @log_task_run
180207def delete_old_request_logs ():
181208 old = timezone .now () - datetime .timedelta (days = 60 )
182209 RequestLog .objects .filter (created__lt = old ).delete ()
183210
184211
185212@periodic_task (crontab (hour = "1" , minute = "3" ))
213+ @log_task_run
186214def delete_old_analyticsevents ():
187215 old = timezone .now () - datetime .timedelta (days = 90 )
188216 AnalyticsEvent .objects .filter (created__lt = old ).delete ()
0 commit comments