mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 06:30:19 -07:00
make timeout decorator for facts have a configurable duration (#16551)
* Add a gather_timeout parameter * update example ansible.cfg * fix play level fact gathering too
This commit is contained in:
parent
ebd3eeec8c
commit
fe8258a378
5 changed files with 24 additions and 0 deletions
|
@ -113,15 +113,21 @@ if platform.system() != 'SunOS':
|
|||
# timeout function to make sure some fact gathering
|
||||
# steps do not exceed a time limit
|
||||
|
||||
GATHER_TIMEOUT=None
|
||||
|
||||
class TimeoutError(Exception):
|
||||
pass
|
||||
|
||||
def timeout(seconds=10, error_message="Timer expired"):
|
||||
|
||||
def decorator(func):
|
||||
def _handle_timeout(signum, frame):
|
||||
raise TimeoutError(error_message)
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
if 'GATHER_TIMEOUT' in globals():
|
||||
if GATHER_TIMEOUT:
|
||||
seconds = GATHER_TIMEOUT
|
||||
signal.signal(signal.SIGALRM, _handle_timeout)
|
||||
signal.alarm(seconds)
|
||||
try:
|
||||
|
@ -3225,6 +3231,9 @@ def get_all_facts(module):
|
|||
# Retrieve module parameters
|
||||
gather_subset = module.params['gather_subset']
|
||||
|
||||
global GATHER_TIMEOUT
|
||||
GATHER_TIMEOUT = module.params['gather_timeout']
|
||||
|
||||
# Retrieve all facts elements
|
||||
additional_subsets = set()
|
||||
exclude_subsets = set()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue