def on_unknown_task(self, body, message, exc): error(UNKNOWN_TASK_ERROR, exc, dump_body(message, body), exc_info=True) try: id_, name = message.headers['id'], message.headers['task'] root_id = message.headers.get('root_id') except KeyError: # proto1 id_, name = body['id'], body['task'] root_id = None request = Bunch( name=name, chord=None, root_id=root_id, correlation_id=message.properties.get('correlation_id'), reply_to=message.properties.get('reply_to'), errbacks=None, ) message.reject_log_error(logger, self.connection_errors) self.app.backend.mark_as_failure( id_, NotRegistered(name), request=request, ) if self.event_dispatcher: self.event_dispatcher.send( 'task-failed', uuid=id_, exception='NotRegistered({0!r})'.format(name), ) signals.task_unknown.send( sender=self, message=message, exc=exc, name=name, id=id_, )
def submit(self, args_from_first_pass: argparse.Namespace, other_args_from_first_pass: list): uid = Uid() self.uid = uid logger.info("FireX ID: %s", uid) logger.info('Logs: %s', uid.logs_dir) self.install_configs = load_new_install_configs(uid.identifier, uid.logs_dir, args_from_first_pass.install_configs) args, others = self.resolve_install_configs_args(args_from_first_pass, other_args_from_first_pass) chain_args = self.process_other_chain_args(args, others) chain_args['uid'] = uid if args.logs_link: self.create_logs_link(args.logs_link) if self.install_configs.has_viewer(): uid.add_viewers(logs_url=self.install_configs.get_logs_root_url()) logger.info(f'Logs URL: {uid.logs_url}') # Create an env file for debugging with open(FileRegistry().get_file(ENVIRON_FILE_REGISTRY_KEY, self.uid.logs_dir), 'w') as f: json.dump(dict(os.environ), fp=f, skipkeys=True, sort_keys=True, indent=4) chain_args = self.convert_chain_args(chain_args) chain_args = self.start_engine(args=args, chain_args=chain_args, uid=uid) # Execute chain try: root_task_name = app.conf.get("root_task") if root_task_name is None: raise NotRegistered("No root task configured") root_task = get_app_task(root_task_name) except NotRegistered as e: logger.error(e) self.main_error_exit_handler(reason=str(e)) sys.exit(-1) self.wait_tracking_services_task_ready() safe_create_initial_run_json(**chain_args) # AsyncResult objects cannot be in memory after the broker (i.e. backend) shutdowns, otherwise errors are # produced when they are garbage collected. We therefore monkey patch AsyncResults to track all instances # (e.g. from unpickle, instantiated directly, etc) so that disable_all_async_results can disable their # references to the backend. monkey_patch_async_result_to_track_instances() root_task_result_promise = root_task.s(submit_app=self, **chain_args).delay() self.copy_submission_log() if args.sync: logger.info("Waiting for chain to complete...") chain_results = self.process_sync(root_task_result_promise, chain_args) results_str = self.format_results_str(chain_results) self.log_results(results_str) self.self_destruct(chain_details=(root_task_result_promise, chain_args), reason="Sync run: completed successfully")
def on_unknown_task(self, body, message, exc): error(UNKNOWN_TASK_ERROR, exc, dump_body(message, body), exc_info=True) id_, name = message.headers['id'], message.headers['task'] message.reject_log_error(logger, self.connection_errors) self.app.backend.mark_as_failure(id_, NotRegistered(name)) if self.event_dispatcher: self.event_dispatcher.send( 'task-failed', uuid=id_, exception='NotRegistered({0!r})'.format(name), ) signals.task_unknown.send( sender=self, message=message, exc=exc, name=name, id=id_, )
def get_app_task(task_short_name: str, all_tasks=None): task_short_name = task_short_name.strip() if all_tasks is None: from firexapp.engine.celery import app all_tasks = app.tasks # maybe it isn't a short name, but a long one if task_short_name in all_tasks: return all_tasks[task_short_name] # Search for an exact match first for key, value in all_tasks.items(): if key.split('.')[-1] == task_short_name: return value # Let's do a case-insensitive search task_name_lower = task_short_name.lower() for key, value in all_tasks.items(): if key.split('.')[-1].lower() == task_name_lower: return value # Can't find a match from celery.exceptions import NotRegistered raise NotRegistered(task_short_name)