Example #1
0
    async def inform_client(self,
                            task: Task,
                            message: str,
                            error: Exception = None) -> None:
        """
        Send information to the server using async writer channel

        :param task: related task
        :param error: related error message
        :param message: message to send
        :return: nothing
        """
        to_send = {'task_info': {}, 'message': '', 'error': ''}

        if task is not None:
            # Add info about the received task
            task_msg = {
                'name': task.get_name(),
                'username': task.get_user(),
                'status': task.get_str_status()
            }
            to_send['task_info'] = task_msg

        to_send['message'] = message

        levelname = LogLevel.DEBUG
        if error is not None and error != 'None':
            error = '{}'.format(error)
            idx = error.find(self.__ERROR_DESC_START)
            if idx >= 0:
                error = error[idx + len(self.__ERROR_DESC_START):]

            to_send['error'] = '{}'.format(error)
            to_send['task_info']['status'] = 'ERROR'
            levelname = LogLevel.ERROR
        self.__log_writer.log('Request response: {}'.format(
            json.dumps(to_send, indent=4)),
                              level=levelname)

        try:
            # Sending response to CKD web application
            self.__out_stream.write(json.dumps(to_send, indent=4).encode())
            await self.__out_stream.drain()
        except Exception as e:
            self.__log_writer.log(
                'Error occurred while responding to the CKD application: {}'.
                format(e))
        self.__log_writer.log('Response sent.', level=LogLevel.DEBUG)
Example #2
0
    def __init_templ_dct(self, templ_dct, task: Task):
        """
        Function to initialize template dictionary with methods of the related Task object

        :param task: related task
        :return: nothing
        """
        templ_dct['__procnum__'] = task.get_procnum()
        templ_dct['__walltime__'] = task.get_walltime()
        templ_dct['__memory__'] = task.get_memory()
        templ_dct['__filename__'] = task.get_filename()
        templ_dct['__descname__'] = task.get_passport_name()
        templ_dct['__jobid__'] = task.get_jobid()
        templ_dct['__name__'] = task.get_name()
        templ_dct['__user__'] = task.get_user()
        templ_dct['__taskdir__'] = task.get_dir_name_for_task(self.workdir)
        templ_dct['__binname__'] = task.get_bin_name()
        templ_dct['__logname__'] = task.get_log_name()
        templ_dct['__workdir__'] = self.__get_workdir()