Skip to content

Commit a645547

Browse files
committed
Added task to set random users online
1 parent fa18184 commit a645547

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

backend/PyMatcha/utils/tasks.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def setup_periodic_tasks(sender, **kwargs):
2323
sender.add_periodic_task(60, update_offline_users.s(), name="Update online users every minute")
2424
sender.add_periodic_task(3600, update_heat_scores.s(), name="Update heat scores every hour")
2525
sender.add_periodic_task(60, update_user_recommendations.s(), name="Update user recommendations every minute")
26+
sender.add_periodic_task(30, take_random_users_online.s(), name="Set 100 random users online every 30 seconds")
2627
sender.add_periodic_task(
2728
600, calc_search_min_max.s(), name="Update Minimum and Maximum scores and ages for search every 10 minutes"
2829
)
@@ -143,3 +144,15 @@ def calc_search_min_max():
143144
minmax = {"min_score": min_score, "max_score": max_score, "min_age": min_age, "max_age": max_age}
144145
redis.set("search_minmax", json.dumps(minmax))
145146
return "Successfully updated min and max ages and scores"
147+
148+
149+
@celery.task
150+
def take_random_users_online():
151+
for user in User.select_random(100):
152+
if not user.skip_recommendations:
153+
# User isn't a bot, so skip him
154+
continue
155+
user.is_online = True
156+
user.date_lastseen = datetime.datetime.utcnow()
157+
user.save()
158+
return "Successfully set 100 users online"

0 commit comments

Comments
 (0)