-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Spooler | ||
======= | ||
|
||
.. automodule:: uwsgiconf.options.spooler | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from uwsgiconf import Section | ||
|
||
|
||
def test_spooler_basics(assert_lines): | ||
|
||
assert_lines([ | ||
'touch-spoolers-reload = /here/a', | ||
], Section().spooler.set_basic_params(touch_reload='/here/a')) | ||
|
||
assert_lines([ | ||
'spooler = home/one', | ||
'spooler = home/two', | ||
], Section().spooler.add(['home/one', 'home/two'])) | ||
|
||
assert_lines([ | ||
'spooler-external = home/two', | ||
], Section().spooler.add('home/two', external=True)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from ..base import OptionsGroup | ||
|
||
|
||
class Spooler(OptionsGroup): | ||
"""Spooler. | ||
.. note:: Supported on: Perl, Python, Ruby. | ||
.. note:: Be sure the ``spooler`` plugin is loaded in your instance, | ||
but generally it is built in by default. | ||
The Spooler is a queue manager built into uWSGI that works like a printing/mail system. | ||
You can enqueue massive sending of emails, image processing, video encoding, etc. | ||
and let the spooler do the hard work in background while your users | ||
get their requests served by normal workers. | ||
http://uwsgi-docs.readthedocs.io/en/latest/Spooler.html | ||
""" | ||
|
||
def set_basic_params( | ||
self, touch_reload=None, quiet=None, process_count=None, max_tasks=None, | ||
order_tasks=None, harakiri=None, change_dir=None, poll_interval=None, signal_as_task=None, | ||
cheap=None): | ||
""" | ||
:param str|unicode|list touch_reload: reload spoolers if the specified file is modified/touched | ||
:param bool quiet: Do not be verbose with spooler tasks. | ||
:param int process_count: Set the number of processes for spoolers. | ||
:param int max_tasks: Set the maximum number of tasks to run before recycling | ||
a spooler (to help alleviate memory leaks). | ||
:param int order_tasks: Try to order the execution of spooler tasks (uses scandir instead of readdir). | ||
:param int harakiri: Set harakiri timeout for spooler tasks. | ||
:param str|unicode change_dir: chdir() to specified directory before each spooler task. | ||
:param int poll_interval: Spooler poll frequency in seconds. Default: 30. | ||
:param bool signal_as_task: Treat signal events as tasks in spooler, | ||
combine used with ``spooler-max-tasks``. Enable this, spooler will treat signal | ||
events as task. run signal handler will also increase the spooler task count. | ||
:param bool cheap: Use spooler cheap mode. | ||
""" | ||
self._set('touch-spoolers-reload', touch_reload, multi=True) | ||
self._set('spooler-quiets', quiet, cast=bool) | ||
self._set('spooler-processes', process_count) | ||
self._set('spooler-max-tasks', max_tasks) | ||
self._set('spooler-ordered', order_tasks, cast=bool) | ||
self._set('spooler-harakiri', harakiri) | ||
self._set('spooler-chdir', change_dir) | ||
self._set('spooler-frequency', poll_interval) | ||
self._set('spooler-signal-as-task', signal_as_task, cast=bool) | ||
self._set('spooler-cheap', cheap, cast=bool) | ||
|
||
return self._section | ||
|
||
def add(self, work_dir, external=False): | ||
"""run a spooler on the specified directory | ||
:param work_dir: | ||
:param bool external: map spoolers requests to a spooler directory managed by an external instance | ||
""" | ||
command = 'spooler' | ||
|
||
if external: | ||
command += '-external' | ||
|
||
self._set(command, work_dir, multi=True) | ||
|
||
return self._section |