Issue with Celery on One-Click OpenLiteSpeed Django Server.

Doulos

New Member
#1
Hello, I am using the One-Click OpenLiteSpeed Django Server. It was working all fine until I installed celery on my project and celery beat. The server is working fine when I run python manage runserver servername:8000 But Lite speed cants serve it it gives error 500. Once i comment celery on the settings.py it show the page again. So the websites works just fine when served by django development server, but cant be served by litespeed. Does it have maybe something to do with the fact that litespeed works with asynchronous tasks??? are them compatible?

i have also noticed that on litespeed panel on port 7080 several options from sidebar are not accessible, I get an error: Invalid tabs 59b9:true
 
Last edited:

Cold-Egg

Administrator
#2
Hi,
May I know if you have installed the celery within virtualenv? Please also try to restart the lswsgi process with the command "killall lswsgi".
If the above method does not help, please check the error log, it should record some useful information.
 

Doulos

New Member
#3
Hi,
May I know if you have installed the celery within virtualenv? Please also try to restart the lswsgi process with the command "killall lswsgi".
If the above method does not help, please check the error log, it should record some useful information.
Hello, thanks for your response, yes everything is fine, the website is working fine: instrai.com.
But I have to comment on settings.py the apps celery and celerybeat.
however, if I uncomment the lines mentioned before the litespeed server returns error 500.
and the strange thing is that I serve it with django development server "python manage runserver", it works just fine.

It has been working like charm until I introduced celery, celery uses asynchronous tasks, I wonder if it have something to do.
 

Doulos

New Member
#4
Hi,
May I know if you have installed the celery within virtualenv? Please also try to restart the lswsgi process with the command "killall lswsgi".
If the above method does not help, please check the error log, it should record some useful information.
yep i have a virtualenvironment and the website works fine, and yes I run killall lswsgi whenever I do any change.
I would like to know if litespeed works fine with celery, isnt there any incompatibility, maybe because of the fact that celery introduces asynchronous tasks?
thanks in advance
 

Doulos

New Member
#5
My problem is simple to reproduce, setup a django app, then install pip install django-celery django-celery-beat
then python manage.py migrate


then register the two apps on settings.py
INSTALLED_APPS = [
...

'celery',
'django_celery_beat',
...
#'rest_framework',

]

at this point litespeed returns error 500

comment the two lines on app and it will work

however when runnning django with python manage.py runserver it works just fine
 

Cold-Egg

Administrator
#6
Hi @Doulos

Package installed
Code:
pip list | grep celery
celery                5.4.0
django-celery-beat    2.6.0
Module added
Code:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'celery',
    'django_celery_beat',
]

Migrated
Code:
python3 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, django_celery_beat, sessions
Running migrations:
  Applying django_celery_beat.0001_initial... OK
  Applying django_celery_beat.0002_auto_20161118_0346... OK
  Applying django_celery_beat.0003_auto_20161209_0049... OK
  Applying django_celery_beat.0004_auto_20170221_0000... OK
  Applying django_celery_beat.0005_add_solarschedule_events_choices... OK
  Applying django_celery_beat.0006_auto_20180322_0932... OK
  Applying django_celery_beat.0007_auto_20180521_0826... OK
  Applying django_celery_beat.0008_auto_20180914_1922... OK
  Applying django_celery_beat.0006_auto_20180210_1226... OK
  Applying django_celery_beat.0006_periodictask_priority... OK
  Applying django_celery_beat.0009_periodictask_headers... OK
  Applying django_celery_beat.0010_auto_20190429_0326... OK
  Applying django_celery_beat.0011_auto_20190508_0153... OK
  Applying django_celery_beat.0012_periodictask_expire_seconds... OK
  Applying django_celery_beat.0013_auto_20200609_0727... OK
  Applying django_celery_beat.0014_remove_clockedschedule_enabled... OK
  Applying django_celery_beat.0015_edit_solarschedule_events_choices... OK
  Applying django_celery_beat.0016_alter_crontabschedule_timezone... OK
  Applying django_celery_beat.0017_alter_crontabschedule_month_of_year... OK
  Applying django_celery_beat.0018_improve_crontab_helptext... OK
Process restart
Code:
killall lswsgi

Page returns "HTTP/1.1 200 OK", and no 500 error.
 

Doulos

New Member
#7
Sorry I forgot two files related to celery correct configuration, my mistake, could you please try for me to add this files? is simple.
they are in mentioned in django celery guide https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html
the __init__.py file of the project needs to have something like:

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)

and there must be a new module celery.py also inside the django project , in my case the name of my project is teletienda

import os
from celery import Celery
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'teletienda.settings')
#es el nombre de la app de Celery
app = Celery('teletienda')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
@app.task(bind=True, ignore_result=True)
def debug_task(self):
print(f'Request: {self.request!r}')


they are need for the celery app to work.

thanks for taking time in help.
with this files included it works fine on development server but litespeed cant serve it.
 

Doulos

New Member
#8
this is the error.log when requesting in the browser and getting error 500

tail -fn16 /usr/local/lsws/logs/error.log

2024-04-23 20:43:25.054677 [INFO] [854] [wsgi:Example:/]: locked pid file [/tmp/lshttpd/Example:_.sock.pid].
2024-04-23 20:43:25.054707 [INFO] [854] [wsgi:Example:/] remove unix socket for detached process: /tmp/lshttpd/Example:_.sock
2024-04-23 20:43:25.054789 [NOTICE] [854] [LocalWorker::workerExec] VHost:Example suExec check uid 65534 gid 65534 setuidmode 0.
2024-04-23 20:43:25.054802 [NOTICE] [854] [LocalWorker::workerExec] Config[wsgi:Example:/]: suExec uid 65534 gid 65534 cmd /usr/local/lsws/fcgi-bin/lswsgi -m /usr/local/lsws/Example/html/teletienda/teletienda/wsgi.py, final uid 65534 gid 65534, flags: 0.
2024-04-23 20:43:25.055125 [NOTICE] [854] [wsgi:Example:/] add child process pid: 62757
2024-04-23 20:43:25.055217 [INFO] [854] [wsgi:Example:/]: unlocked pid file [/tmp/lshttpd/Example:_.sock.pid].
2024-04-23 20:43:25.292073 [NOTICE] [854] [152.206.190.91:25510:HTTP2-15#Example] Premature end of response header.
 

Cold-Egg

Administrator
#9
Check the std error log, you might need to fix something from the Python code,

Code:
ImportError: cannot import name 'Celery' from partially initialized module 'celery' (most likely due to a circular import)
It's a Djando-related issue. To fix it, please update the celery.py file to a new name, e.g. celery2.py, then update the from .celery import app as celery_app to from .celery2 import app as celery_app from the __init__.py file.
 
#10
A lo cubano, compadre usted es el caballo. Que Dios te bendiga, con eso creo que se resolvio todo. Muchas Gracias!!!
in English , You are the man, God Bless you, I think with your last suggestion everything is working fine again. Thanks very much.
 
Top