uwsgi
uwsgi copied to clipboard
Spooler decorator and external spooler does not work well together
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:
- create a dedicated decorator for external spoolers that does only checks for the spooler-external variable
- check that any of spooler OR spooler-external are configured in the spool decorator before decide to return error
I ended up solving with this monkey patch: it only adds
and "spooler-external" not in uwsgi.optat 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
Any hope this get reviewed/merged somehow?
@parruc feel free to open a PR