##// END OF EJS Templates
subscribers: use shlex in the async-subscriber directly
milka -
r4582:5c8aeb25 stable
parent child Browse files
Show More
@@ -48,7 +48,7 b' def includeme(config):'
48
48
49 # If a reload command is set add a subscriber to execute it on
49 # If a reload command is set add a subscriber to execute it on
50 # configuration changes.
50 # configuration changes.
51 reload_cmd = shlex.split(settings[config_keys.reload_command])
51 reload_cmd = settings[config_keys.reload_command]
52 if reload_cmd:
52 if reload_cmd:
53 reload_timeout = settings[config_keys.reload_timeout] or None
53 reload_timeout = settings[config_keys.reload_timeout] or None
54 reload_subscriber = AsyncSubprocessSubscriber(
54 reload_subscriber = AsyncSubprocessSubscriber(
@@ -18,6 +18,8 b''
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 import io
20 import io
21 import shlex
22
21 import math
23 import math
22 import re
24 import re
23 import os
25 import os
@@ -357,10 +359,16 b' class AsyncSubscriber(Subscriber):'
357 class AsyncSubprocessSubscriber(AsyncSubscriber):
359 class AsyncSubprocessSubscriber(AsyncSubscriber):
358 """
360 """
359 Subscriber that uses the subprocess32 module to execute a command if an
361 Subscriber that uses the subprocess32 module to execute a command if an
360 event is received. Events are handled asynchronously.
362 event is received. Events are handled asynchronously::
363
364 subscriber = AsyncSubprocessSubscriber('ls -la', timeout=10)
365 subscriber(dummyEvent) # running __call__(event)
366
361 """
367 """
362
368
363 def __init__(self, cmd, timeout=None):
369 def __init__(self, cmd, timeout=None):
370 if not isinstance(cmd, (list, tuple)):
371 cmd = shlex.split(cmd)
364 super(AsyncSubprocessSubscriber, self).__init__()
372 super(AsyncSubprocessSubscriber, self).__init__()
365 self._cmd = cmd
373 self._cmd = cmd
366 self._timeout = timeout
374 self._timeout = timeout
@@ -384,6 +392,6 b' class AsyncSubprocessSubscriber(AsyncSub'
384 log.exception('Error while executing command.')
392 log.exception('Error while executing command.')
385 if e.output:
393 if e.output:
386 log.error('Command output: %s', e.output)
394 log.error('Command output: %s', e.output)
387 except:
395 except Exception:
388 log.exception(
396 log.exception(
389 'Exception while executing command %s.', cmd)
397 'Exception while executing command %s.', cmd)
General Comments 0
You need to be logged in to leave comments. Login now