Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RQ WorkerPool is not loading models at all #651

Open
FlavienJP opened this issue Feb 27, 2024 · 0 comments · May be fixed by #655
Open

RQ WorkerPool is not loading models at all #651

FlavienJP opened this issue Feb 27, 2024 · 0 comments · May be fixed by #655

Comments

@FlavienJP
Copy link

Hi,

This issue is close to #650, but we are not in the same context.

I need my jobs to read/write models on database, so I've made a simple task to check that it's working.

@job("data-tasks", timeout=3600)
def Test(instance):
    print(instance)

When using a single worker, no issue, I can pass the id, or the object, without any issue.

python manage.py rqworker data-tasks notifications

16:49:47 data-tasks: data.methods.Test(<Instance: [MyObject] LVX Vlxx>) (9ea7c2a5-420e-4849-873a-fe378708f760)
[MyObject] LVX Vlxx
16:49:50 data-tasks: Job OK (9ea7c2a5-420e-4849-873a-fe378708f760)

But when I'm using a pool of 1 worker, then it seems that something is going wrong, the content of Django App is not loaded.

python manage.py rqworker-pool data-tasks notifications --num-workers 1

16:51:36 data-tasks: data.methods.Test(<Instance: [MyObject] LVX Vlxx>) (76b6fb38-8f10-4e78-9231-9fafc7c29042)
16:51:37 [Job 76b6fb38-8f10-4e78-9231-9fafc7c29042]: exception raised while executing (<DeserializationError>)
Traceback (most recent call last):
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/rq/job.py", line 486, in _deserialize_data
    self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/django/db/models/base.py", line 2612, in model_unpickle
    model = apps.get_model(*model_id)
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/django/apps/registry.py", line 201, in get_model
    self.check_models_ready()
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/django/apps/registry.py", line 143, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/rq/worker.py", line 1422, in perform_job
    self.prepare_job_execution(job, remove_from_intermediate_queue)
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/rq/worker.py", line 1351, in prepare_job_execution
    self.procline(msg.format(job.func_name, job.origin, time.time()))
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/rq/job.py", line 520, in func_name
    self._deserialize_data()
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/rq/job.py", line 488, in _deserialize_data
    raise DeserializationError() from e
rq.exceptions.DeserializationError

I've also tried to pass only the ID and get the object, then I've an error that is telling that AbstractUsercannot be loaded.

 File "/Users/mymac/PycharmProjects/MyApp/data/models.py", line 4, in <module>
    from django.contrib.auth.models import User
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 58, in <module>
    class AbstractBaseUser(models.Model):
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/django/db/models/base.py", line 129, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/django/apps/registry.py", line 260, in get_containing_app_config
    self.check_apps_ready()
  File "/Users/mymac/PycharmProjects/MyApp/.venv/lib/python3.10/site-packages/django/apps/registry.py", line 138, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

So it seems to me that worker pool is missing something.

Thanks for your help,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant