Koed00 / django-q

A multiprocessing distributed task queue for Django
https://django-q.readthedocs.org
MIT License
1.82k stars 284 forks source link

Issues with multiDB django setups. #473

Open c-goosen opened 4 years ago

c-goosen commented 4 years ago

Getting the following output on a Multi DB setup.

Version: 3.1.1 Python Version: Python 3.8.3

ENV: Amazon Linux on AWS EKS Fargate

23:43:37 [Q] INFO Q Cluster bravo-wyoming-idaho-minnesota running. 23:44:08 [Q] ERROR select_for_update cannot be used outside of a transaction. 23:44:39 [Q] ERROR select_for_update cannot be used outside of a transaction. 23:45:10 [Q] ERROR select_for_update cannot be used outside of a transaction. 23:45:27 [Q] INFO Process-1:1 processing [red-fruit-princess-potato] 23:45:40 [Q] ERROR select_for_update cannot be used outside of a transaction.

Investigating some more. Will replicate locally.

Currently fixed it by having separate settings from ENV vars for django-q containers.

Any ideas?

Koed00 commented 4 years ago
        with db.transaction.atomic(using=Schedule.objects.db):
            for s in (
                Schedule.objects.select_for_update()
                .exclude(repeats=0)
                .filter(next_run__lt=timezone.now())
            ):

I'm guessing it can't find the db for the Schedule model in the db router. Did you use set the db for the Schedule in the router or just set the ORM setting?

Koed00 commented 4 years ago

If I'm right and you want all of the django_q models to run on a seperate database, not just the queue, then we would have to implement db selection in the model managers and the admins.

telmobarros commented 3 years ago

Hello, please consider giving a look on #434 .

I had split correctly the default database from the django_q and was having the same problem. Found out was using an older version (1.2.1) and it was fixed on 1.2.2 .

telmobarros commented 3 years ago

Duplicate of #434