Пример #1
0
def query_task():
    tasks = JobSaver.query_task(**request.json)
    if not tasks:
        return get_json_result(retcode=101,
                               retmsg='Query task failed, no task found.')
    task_filters = [
        'play_id', 'task_id', 'task_name', 'role', 'create_time', 'start_time',
        'end_time', 'status', 'elapsed'
    ]
    return get_json_result(retmsg="Query task successfully.",
                           data=tasks[0].to_json(task_filters))
Пример #2
0
    def _task_start(self, task, prefix=None):
        # Create task from this function
        # schedule_logger(self._job_id).info(f"<CREATING TASK> Trying to create task. Task id: {task._uuid}, task name: {task._attributes.get('name')}, prefix: {prefix}")
        schedule_logger(self._job_id).info(
            f"<CREATING TASK> Trying to create task. Task id: {task._uuid}, task name: {task._attributes.get('name')}, module: {task._role}."
        )
        if self._retry:
            tasks = JobSaver.query_task(play_id=self._play_id)
            if tasks:
                pass
        task_info = {
            'job_id': self._job_id,
            'play_id': self._play_id,
            'task_id': task._uuid,
            'task_name': task._attributes.get('name'),
            'status': TaskStatus.WAITING,
            'create_time': current_timestamp(),
            'role': task._role,
        }
        JobSaver.create_task(task_info)
        schedule_logger(self._job_id).info(
            f"create task with id {task._uuid} successfully")

        # try:
        #     schedule_logger(self._job_id).info(f"task role: {task._role}")
        # except Exception:
        #     pass
        # stat_logger.info(f"<<<<<>>>>> in _task_start, task name: {task._attributes.get('name')}, task id: {task._uuid}")

        # Cache output prefix for task if provided
        # This is needed to properly display 'RUNNING HANDLER' and similar
        # when hiding skipped/ok task results
        if prefix is not None:
            self._task_type_cache[task._uuid] = prefix

        # Preserve task name, as all vars may not be available for templating
        # when we need it later
        if self._play.strategy == 'free':
            # Explicitly set to None for strategy 'free' to account for any cached
            # task title from a previous non-free play
            self._last_task_name = None
        else:
            self._last_task_name = task.get_name().strip()

            # Display the task banner immediately if we're not doing any filtering based on task result
            if self.display_skipped_hosts and self.display_ok_hosts:
                self._print_task_banner(task)
Пример #3
0
def query_play():
    plays = JobSaver.query_play(**request.json)
    if not plays:
        return get_json_result(retcode=101,
                               retmsg='Query play failed, no play found.')
    play_filters = [
        'job_id', 'play_id', 'create_time', 'start_time', 'end_time', 'status',
        'elapsed'
    ]
    data = plays[0].to_json(filters=play_filters)
    tasks = JobSaver.query_task(reverse=False, **request.json)
    if tasks:
        task_filters = [
            'play_id', 'task_id', 'task_name', 'role', 'create_time',
            'start_time', 'end_time', 'status', 'elapsed'
        ]
        data['f_tasks'] = [task.to_json(task_filters) for task in tasks]
    return get_json_result(retmsg="Query play successfully.", data=data)