Skip to content

Commit

Permalink
Feat celery run (#860)
Browse files Browse the repository at this point in the history
* avoid calling post save signals
* remove stale celery ids that prevent new services from starting
  • Loading branch information
mgogoulos authored Nov 10, 2023
1 parent e7ce9ef commit e9739ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion deploy/docker/prestart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ X"$ENABLE_MIGRATIONS" = X"yes" ]; then
echo "Running migrations service"
python manage.py migrate
EXISTING_INSTALLATION=`echo "from users.models import User; print(User.objects.exists())" |python manage.py shell`
if [ "$EXISTING_INSTALLATION" = "True" ]; then
if [ "$EXISTING_INSTALLATION" = "True" ]; then
echo "Loaddata has already run"
else
echo "Running loaddata and creating admin user"
Expand Down Expand Up @@ -67,4 +67,5 @@ fi
if [ X"$ENABLE_CELERY_LONG" = X"yes" ] ; then
echo "Enabling celery-long task worker"
cp deploy/docker/supervisord/supervisord-celery_long.conf /etc/supervisor/conf.d/supervisord-celery_long.conf
rm /var/run/mediacms/* -f # remove any stale id, so that on forced restarts of celery workers there are no stale processes that prevent new ones
fi
10 changes: 7 additions & 3 deletions files/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,11 @@ def save_user_action(user_or_session, friendly_token=None, action="watch", extra

if action == "watch":
media.views += 1
media.save(update_fields=["views"])
Media.objects.filter(friendly_token=friendly_token).update(views=media.views)

# update field without calling save, to avoid post_save signals being triggered
# same in other actions

elif action == "report":
media.reported_times += 1

Expand All @@ -659,10 +663,10 @@ def save_user_action(user_or_session, friendly_token=None, action="watch", extra
)
elif action == "like":
media.likes += 1
media.save(update_fields=["likes"])
Media.objects.filter(friendly_token=friendly_token).update(likes=media.likes)
elif action == "dislike":
media.dislikes += 1
media.save(update_fields=["dislikes"])
Media.objects.filter(friendly_token=friendly_token).update(dislikes=media.dislikes)

return True

Expand Down

0 comments on commit e9739ba

Please sign in to comment.