def init_api(self): self.api = sly.AgentAPI(constants.TOKEN(), constants.SERVER_ADDRESS(), self.logger, constants.TIMEOUT_CONFIG_PATH()) if 'user_api_key' in self.info: self.public_api = sly.Api(constants.SERVER_ADDRESS(), self.info['user_api_key']) self.public_api.add_additional_field('taskId', self.info['task_id']) self.public_api_context = self.public_api.task.get_context(self.info['task_id'])
def init_api(self): self.api = sly.AgentAPI(constants.TOKEN(), constants.SERVER_ADDRESS(), self.logger, constants.TIMEOUT_CONFIG_PATH()) if self._user_api_key is not None: self.public_api = sly.Api(constants.SERVER_ADDRESS(), self._user_api_key, external_logger=self.logger, retry_count=constants.PUBLIC_API_RETRY_LIMIT()) task_id = self.info['task_id'] self.public_api.add_additional_field('taskId', task_id) self.public_api.add_header('x-task-id', str(task_id)) self.public_api_context = self.public_api.task.get_context(task_id)
def download_step(self): if self.info.get('nn_model', None) is None: self.logger.critical('TASK_NN_EMPTY') raise ValueError('TASK_NN_EMPTY') self.data_mgr.download_nn(self.info['nn_model']['title'], self.dir_model) #@TODO: only for compatibility with old models shutil.move(self.dir_model, self.dir_model + '_delme') shutil.move(os.path.join(self.dir_model + '_delme', self.info['nn_model']['title']), self.dir_model) sly.fs.remove_dir(self.dir_model + '_delme') out_cfg = { **self.info['task_settings'], # settings from server 'connection': { 'server_address': constants.SERVER_ADDRESS(), 'token': constants.TOKEN(), 'task_id': str(self.info['task_id']), }, 'model_settings': self.info['task_settings'] } json.dump(out_cfg, open(self.config_path1, 'w')) # Deprecated 'task_settings.json' json.dump(out_cfg, open(self.config_path2, 'w')) # New style task_config.json self.report_step_done(TaskStep.DOWNLOAD)
def __init__(self): self.logger = sly.get_task_logger('agent') sly.change_formatters_default_values(self.logger, 'service_type', sly.ServiceType.AGENT) sly.change_formatters_default_values(self.logger, 'event_type', sly.EventType.LOGJ) self.log_queue = LogQueue() add_task_handler(self.logger, self.log_queue) sly.add_default_logging_into_file(self.logger, constants.AGENT_LOG_DIR()) self.logger.info('Agent comes back...') self.task_pool_lock = threading.Lock() self.task_pool = {} # task_id -> task_manager (process_id) self.thread_pool = ThreadPoolExecutor(max_workers=10) self.thread_list = [] self.daemons_list = [] sly.fs.clean_dir(constants.AGENT_TMP_DIR()) self._stop_missed_containers() self.docker_api = docker.from_env(version='auto') self._docker_login() self.logger.info('Agent is ready to get tasks.') self.api = sly.AgentAPI(constants.TOKEN(), constants.SERVER_ADDRESS(), self.logger, constants.TIMEOUT_CONFIG_PATH()) self.agent_connect_initially() self.logger.info('Agent connected to server.')
def main_step_envs(self): envs = super().main_step_envs() envs.update({ 'SERVER_ADDRESS': worker_constants.SERVER_ADDRESS(), 'API_TOKEN': self._user_api_key, SUPERVISELY_TASK_ID: str(self.info['task_id']) }) return envs
def __init__(self): self.logger = sly.get_task_logger('agent') sly.change_formatters_default_values(self.logger, 'service_type', sly.ServiceType.AGENT) sly.change_formatters_default_values(self.logger, 'event_type', sly.EventType.LOGJ) self.log_queue = LogQueue() add_task_handler(self.logger, self.log_queue) sly.add_default_logging_into_file(self.logger, constants.AGENT_LOG_DIR()) self._stop_log_event = threading.Event() self.executor_log = ThreadPoolExecutor(max_workers=1) self.future_log = None self.logger.info('Agent comes back...') self.task_pool_lock = threading.Lock() self.task_pool = {} # task_id -> task_manager (process_id) self.thread_pool = ThreadPoolExecutor(max_workers=10) self.thread_list = [] self.daemons_list = [] self._remove_old_agent() self._validate_duplicated_agents() sly.fs.clean_dir(constants.AGENT_TMP_DIR()) self._stop_missed_containers(constants.TASKS_DOCKER_LABEL()) # for compatibility with old plugins self._stop_missed_containers(constants.TASKS_DOCKER_LABEL_LEGACY()) self.docker_api = docker.from_env( version='auto', timeout=constants.DOCKER_API_CALL_TIMEOUT()) self._docker_login() self.logger.info('Agent is ready to get tasks.') self.api = sly.AgentAPI(constants.TOKEN(), constants.SERVER_ADDRESS(), self.logger, constants.TIMEOUT_CONFIG_PATH()) self.agent_connect_initially() self.logger.info('Agent connected to server.')
def main_step_envs(self): return { 'SERVER_ADDRESS': worker_constants.SERVER_ADDRESS(), 'API_TOKEN': self._user_api_key, SUPERVISELY_TASK_ID: str(self.info['task_id']) }
def main_step_envs(self): return { 'SERVER_ADDRESS': worker_constants.SERVER_ADDRESS(), 'API_TOKEN': self._user_api_key }