gavinwahl / django-postgres-queue

A task queue for django
BSD 2-Clause "Simplified" License
120 stars 14 forks source link

always eager #6

Closed jtrain closed 4 years ago

jtrain commented 4 years ago

I know celery discourages use of always eager. But I love it, and I always will.

I have written my own version of always eager internally, but it might be nice to add to the library? It is useful during end-to-end testing where you definitely want the thing you are queuing to run during the test.

gavinwahl commented 4 years ago

I also don't like always eager. I do this in my tests when I want to run the tasks:

while queue.run_once(): pass
gavinwahl commented 4 years ago

If you really want it you can do it with a subclass, something like:

class EagerAtLeastOnceQueue(AtLeastOnceQueue):
    def enqueue(self, *args, **kwargs):
        job = super().enqueue(*args, **kwargs)
        if settings.ALWAYS_EAGER:
            self.run_job(job)
        return job
jtrain commented 4 years ago

Its worthwhile documenting how to do always eager. I'll put together some docs.