Skip to content

Commit fb665a1

Browse files
committed
Added the celery task
1 parent 4888ac0 commit fb665a1

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

backend/PyMatcha/utils/tasks.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import datetime
22
import json
3+
import random
34
from math import ceil
45

56
from PyMatcha import celery
67
from PyMatcha import redis
78
from PyMatcha.models.message import Message
89
from PyMatcha.models.user import User
10+
from PyMatcha.utils.bot_actions import botaction_like
11+
from PyMatcha.utils.bot_actions import botaction_message_new_conversation
12+
from PyMatcha.utils.bot_actions import botaction_respond_to_unread
13+
from PyMatcha.utils.bot_actions import botaction_send_message_over_old_one
14+
from PyMatcha.utils.bot_actions import botaction_unlike
15+
from PyMatcha.utils.bot_actions import botaction_view
916
from PyMatcha.utils.recommendations import create_user_recommendations
1017

1118
BASE_HEAT_SCORE = 30
@@ -28,6 +35,7 @@ def setup_periodic_tasks(sender, **kwargs):
2835
sender.add_periodic_task(
2936
600, calc_search_min_max.s(), name="Update Minimum and Maximum scores and ages for search every 10 minutes"
3037
)
38+
sender.add_periodic_task(30, random_bot_action.s(), name="Have the only bots do an action")
3139

3240

3341
@celery.task
@@ -145,6 +153,17 @@ def take_random_users_online():
145153

146154
@celery.task
147155
def random_bot_action():
148-
for user in User.get_multis(skip_recommendations=True):
149-
# TODO: Check notifications
150-
pass
156+
for user in User.get_multis(skip_recommendations=True, is_online=True):
157+
bot_actions = [
158+
None,
159+
botaction_view,
160+
botaction_like,
161+
botaction_respond_to_unread,
162+
botaction_message_new_conversation,
163+
botaction_send_message_over_old_one,
164+
botaction_unlike,
165+
]
166+
selected_action = random.choices(bot_actions, cum_weights=(100, 100, 95, 90, 90, 80, 50), k=1)
167+
if selected_action[0]:
168+
# Has to have the [0] because random.choices return a list
169+
selected_action[0](user)

0 commit comments

Comments
 (0)