Feat celery run (#860)

* avoid calling post save signals
* remove stale celery ids that prevent new services from starting
This commit is contained in:
Markos Gogoulos 2023-11-10 16:06:17 +02:00 committed by GitHub
parent e7ce9ef5c0
commit e9739bab45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -7,7 +7,7 @@ if [ X"$ENABLE_MIGRATIONS" = X"yes" ]; then
echo "Running migrations service" echo "Running migrations service"
python manage.py migrate python manage.py migrate
EXISTING_INSTALLATION=`echo "from users.models import User; print(User.objects.exists())" |python manage.py shell` 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" echo "Loaddata has already run"
else else
echo "Running loaddata and creating admin user" echo "Running loaddata and creating admin user"
@ -67,4 +67,5 @@ fi
if [ X"$ENABLE_CELERY_LONG" = X"yes" ] ; then if [ X"$ENABLE_CELERY_LONG" = X"yes" ] ; then
echo "Enabling celery-long task worker" echo "Enabling celery-long task worker"
cp deploy/docker/supervisord/supervisord-celery_long.conf /etc/supervisor/conf.d/supervisord-celery_long.conf 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 fi

View File

@ -644,7 +644,11 @@ def save_user_action(user_or_session, friendly_token=None, action="watch", extra
if action == "watch": if action == "watch":
media.views += 1 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": elif action == "report":
media.reported_times += 1 media.reported_times += 1
@ -659,10 +663,10 @@ def save_user_action(user_or_session, friendly_token=None, action="watch", extra
) )
elif action == "like": elif action == "like":
media.likes += 1 media.likes += 1
media.save(update_fields=["likes"]) Media.objects.filter(friendly_token=friendly_token).update(likes=media.likes)
elif action == "dislike": elif action == "dislike":
media.dislikes += 1 media.dislikes += 1
media.save(update_fields=["dislikes"]) Media.objects.filter(friendly_token=friendly_token).update(dislikes=media.dislikes)
return True return True