diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index c8f5a342..5befe79b 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -500,6 +500,28 @@ void init_uwsgi_embedded_module() { } } + if (uwsgi.spoolers) { + int sc = 0; + struct uwsgi_spooler *uspool = uwsgi.spoolers; + while(uspool) { sc++; uspool = uspool->next;} + + PyObject *py_spooler_tuple = PyTuple_New(sc); + + uspool = uwsgi.spoolers; + sc = 0; + + while(uspool) { + PyTuple_SetItem(py_spooler_tuple, sc, PyString_FromString(uspool->dir)); + sc++; + uspool = uspool->next; + } + + if (PyDict_SetItemString(up.embedded_dict, "spoolers", py_spooler_tuple)) { + PyErr_Print(); + exit(1); + } + } + if (PyDict_SetItemString(up.embedded_dict, "SPOOL_RETRY", PyInt_FromLong(-1))) { PyErr_Print(); diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 18558271..d986f78b 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -1512,6 +1512,8 @@ PyObject *py_uwsgi_send_spool(PyObject * self, PyObject * args, PyObject *kw) { char *body = NULL; size_t body_len= 0; + struct uwsgi_spooler *uspool = uwsgi.spoolers; + spool_dict = PyTuple_GetItem(args, 0); if (spool_dict) { @@ -1531,6 +1533,17 @@ PyObject *py_uwsgi_send_spool(PyObject * self, PyObject * args, PyObject *kw) { return PyErr_Format(PyExc_ValueError, "The argument of spooler callable must be a dictionary"); } + // TODO if "spooler" is a num, get the spooler by id, otherwise get it by directory + PyObject *py_spooler = uwsgi_py_dict_get(spool_dict, "spooler"); + if (py_spooler) { + if (PyString_Check(py_spooler)) { + uspool = uwsgi_get_spooler_by_name(PyString_AsString(py_spooler)); + if (!uspool) { + return PyErr_Format(PyExc_ValueError, "Unknown spooler requested"); + } + } + } + PyObject *pyprio = uwsgi_py_dict_get(spool_dict, "priority"); if (pyprio) { if (PyInt_Check(pyprio)) { @@ -1633,7 +1646,7 @@ PyObject *py_uwsgi_send_spool(PyObject * self, PyObject * args, PyObject *kw) { if (numprio) { priority = uwsgi_num2str(numprio); } - i = spool_request(uwsgi.spoolers, spool_filename, uwsgi.workers[0].requests + 1, wsgi_req->async_id, spool_buffer, cur_buf - spool_buffer, priority, at, body, body_len); + i = spool_request(uspool, spool_filename, uwsgi.workers[0].requests + 1, wsgi_req->async_id, spool_buffer, cur_buf - spool_buffer, priority, at, body, body_len); if (priority) { free(priority); } diff --git a/spooler.c b/spooler.c index 9a8bd52e..d097584b 100644 --- a/spooler.c +++ b/spooler.c @@ -12,6 +12,20 @@ void spooler_manage_task(char *, char *); // fake function to allow waking the spooler void spooler_wakeup() {} +struct uwsgi_spooler *uwsgi_get_spooler_by_name(char *name) { + + struct uwsgi_spooler *uspool = uwsgi.spoolers; + + while(uspool) { + if (!strcmp(uspool->dir, name)) { + return uspool; + } + uspool = uspool->next; + } + + return NULL; +} + pid_t spooler_start(struct uwsgi_spooler *uspool) { int i; diff --git a/uwsgi.h b/uwsgi.h index 0163c1b8..6ca1c8e3 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2590,6 +2590,8 @@ void *uwsgi_malloc_shared(size_t); struct uwsgi_spooler *uwsgi_new_spooler(char *); +struct uwsgi_spooler *uwsgi_get_spooler_by_name(char *); + #ifdef UWSGI_AS_SHARED_LIBRARY int uwsgi_init(int, char **, char **); #endif