uwsgi icon indicating copy to clipboard operation
uwsgi copied to clipboard

Spooler decorator and external spooler does not work well together

Open parruc opened this issue 5 years ago • 3 comments

Some context: I use 4 django instances to serve web requests and a dedicated instance with different timeouts and configurations to manage spool request. All instances share the same filesystem so the same spooler directory is available to all processes.

In the uwsgi configuration of the spooler instance I have

spooler: /path/to/spooler

In the django uwsgi configuration I have:

spooler-external: /path/to/spooler

The Issuse When I try to import the methods decorated with @spool from my "normal" django instances to enqueue something I get the error "you have to enable the uWSGI spooler to use method_name" Looking at the code I saw it's because it checks if, on the current instance configuration, I have a spooler configured which I have not cause I have an external one.

The possible solutions Two possible solutions IMHO:

  1. create a dedicated decorator for external spoolers that does only checks for the spooler-external variable
  2. check that any of spooler OR spooler-external are configured in the spool decorator before decide to return error

parruc avatar Nov 24 '20 11:11 parruc

I ended up solving with this monkey patch: it only adds

 and "spooler-external" not in uwsgi.opt
at the end of the condition.

I dont see any drawback but maybe someone smarter than me can take a look at it.


try:
    import uwsgi
    import uwsgidecorators
except ImportError:
    uwsgi = False

# BBB: monkey patch untill https://github.com/unbit/uwsgi/issues/2258 is solved
if uwsgi:
    def new_init(self, f, pass_arguments):
        if 'spooler' not in uwsgi.opt and "spooler-external" not in uwsgi.opt:
            raise Exception(
                "you have to enable the uWSGI spooler to use @%s decorator" % self.__class__.__name__)
        self.f = f
        uwsgidecorators.spooler_functions[self.f.__name__] = self.f
        # For backward compatibility (uWSGI < 1.9.13)
        self.f.spool = self.__call__
        self.pass_arguments = pass_arguments
        self.base_dict = {'ud_spool_func': self.f.__name__}_}
uwsgidecorators._spoolraw.__init__ = new_init

parruc avatar Dec 10 '20 08:12 parruc

Any hope this get reviewed/merged somehow?

parruc avatar Jul 12 '23 12:07 parruc

@parruc feel free to open a PR

xrmx avatar Jul 12 '23 15:07 xrmx