File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import logging
2+
3+ from celery import shared_task
4+
5+ from apps .community_dashboard .management .commands .update_aggregated_data import Command as UpdateAggregateCommand
6+ from main .cache import CeleryLock
7+ from main .cronjobs import TimeConstants
8+
9+ logger = logging .getLogger (__name__ )
10+
11+
12+ @shared_task
13+ def update_aggregated_data ():
14+ with CeleryLock .redis_lock (
15+ CeleryLock .Key .COMMUNITY_DASHBOARD_UPDATE_AGGREGATE ,
16+ lock_expire = TimeConstants .SECONDS_IN_A_HOUR ,
17+ ) as acquired :
18+ if not acquired :
19+ logger .warning ("Community Dashboard update aggregate already running" )
20+ return
21+
22+ UpdateAggregateCommand ().handle ()
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class Key:
2121 TUTORIAL_PUSH_TO_FIREBASE = "TUTORIAL_PUSH_TO_FIREBASE_{0}"
2222
2323 MAPPING_SESSION_PULL_FROM_FIREBASE = "MAPPING_SESSION_PULL_FROM_FIREBASE"
24+ COMMUNITY_DASHBOARD_UPDATE_AGGREGATE = "COMMUNITY_DASHBOARD_UPDATE_AGGREGATE"
2425
2526 USERS_PULL_FROM_FIREBASE = "USERS_PULL_FROM_FIREBASE"
2627 USER_GROUP_MEMBERSHIPS_PULL_FROM_FIREBASE = "USER_GROUP_MEMBERSHIPS_PULL_FROM_FIREBASE"
Original file line number Diff line number Diff line change 1111
1212
1313class TimeConstants :
14+ SECONDS_IN_A_DAY = 24 * 60 * 60
1415 SECONDS_IN_A_HOUR = 60 * 60
1516 SECONDS_IN_A_WEEK = 7 * 24 * 60 * 60
1617 SECONDS_IN_A_MINUTE = 60
1718
1819 EVERY_WEEK = crontab (minute = "1" , hour = "1" , day_of_week = "1" )
20+ EVERY_DAY = crontab (minute = "1" , hour = "1" )
1921 EVERY_HOUR = crontab (minute = "0" , hour = "*" )
2022 EVERY_2_MINUTES = crontab (minute = "*/2" )
2123 EVERY_1_MINUTES = crontab (minute = "*/1" )
@@ -128,6 +130,16 @@ class CronJob(typing.NamedTuple):
128130 max_runtime = 2 ,
129131 ),
130132 ),
133+ "update_community_dashboard_aggregated_data" : CronJob (
134+ task = "apps.community_dashboard.tasks.update_aggregated_data" ,
135+ schedule = TimeConstants .EVERY_DAY ,
136+ options = CronJobOption (expires = TimeConstants .SECONDS_IN_A_DAY ),
137+ sentry_config = CronJobSentryConfig (
138+ failure_issue_threshold = 1 ,
139+ checkin_margin = 10 ,
140+ max_runtime = 10 ,
141+ ),
142+ ),
131143 # Queue uptime
132144 ** {
133145 f"celery_queue_uptime_{ celery_queue .name } " : CronJob (
You can’t perform that action at this time.
0 commit comments