in curator/helpers/waiters.py [0:0]
def task_check(client, task_id=None):
"""
This function calls `client.tasks.`
:py:meth:`~.elasticsearch.client.TasksClient.get` with the provided
``task_id``. If the task data contains ``'completed': True``, then it will
return ``True``. If the task is not completed, it will log some information
about the task and return ``False``
:param client: A client connection object
:param task_id: The task id
:type client: :py:class:`~.elasticsearch.Elasticsearch`
:type task_id: str
:rtype: bool
"""
logger = logging.getLogger(__name__)
try:
warnings.filterwarnings("ignore", category=GeneralAvailabilityWarning)
task_data = client.tasks.get(task_id=task_id)
except Exception as err:
msg = (
f'Unable to obtain task information for task_id "{task_id}". '
f'Exception {err}'
)
raise CuratorException(msg) from err
task = task_data['task']
completed = task_data['completed']
if task['action'] == 'indices:data/write/reindex':
logger.debug('It\'s a REINDEX TASK')
logger.debug('TASK_DATA: %s', task_data)
logger.debug('TASK_DATA keys: %s', list(task_data.keys()))
if 'response' in task_data:
response = task_data['response']
if response['failures']:
msg = f'Failures found in reindex response: {response["failures"]}'
raise FailedReindex(msg)
running_time = 0.000000001 * task['running_time_in_nanos']
logger.debug('Running time: %s seconds', running_time)
descr = task['description']
if completed:
completion_time = (running_time * 1000) + task['start_time_in_millis']
time_string = strftime('%Y-%m-%dT%H:%M:%SZ', localtime(completion_time / 1000))
logger.info('Task "%s" completed at %s.', descr, time_string)
retval = True
else:
# Log the task status here.
logger.debug('Full Task Data: %s', task_data)
msg = (
f'Task "{descr}" with task_id "{task_id}" has been running for '
f'{running_time} seconds'
)
logger.info(msg)
retval = False
return retval