def should_fail(_, _obj): raise Failure( description="Foolure", metadata_entries=[ EventMetadataEntry.text(label="label", text="text", description="description") ], )
def _execute_item(self, context, item_name, forward_resource_stacks, backward_resources): """Executes the given item using the given forward resource stacks and backward resources. Returns list of output resource stacks. Called by ``_make_forward_solid_def.compute_fn``. For each element yielded by ``_filtered_resources_iterator``, spawns a thread that runs ``_execute_item_filtered``. Args: context item_name (str) forward_resource_stacks (list(tuple(ProjectItemResource))) backward_resources (list(ProjectItemResource)) Returns: list(tuple(ProjectItemResource)) """ success = [ItemExecutionFinishState.NEVER_FINISHED] output_resources_list = [] threads = [] resources_iterator = self._filtered_resources_iterator( item_name, forward_resource_stacks, backward_resources, create_timestamp()) for flt_fwd_resources, flt_bwd_resources, filter_id in resources_iterator: item = self._make_item(item_name, ED.FORWARD) if not item.ready_to_execute(self._settings): if not self._execution_permits[self._solid_names[ item_name]]: # Exclude if not selected success[0] = ItemExecutionFinishState.EXCLUDED else: # Fail if selected context.log.error( f"compute_fn() FAILURE in: '{item_name}', not ready for forward execution" ) success[0] = ItemExecutionFinishState.FAILURE else: item.filter_id = filter_id thread = threading.Thread( target=self._execute_item_filtered, args=(item, flt_fwd_resources, flt_bwd_resources, output_resources_list, success), ) threads.append(thread) thread.start() for thread in threads: thread.join() if success[0] == ItemExecutionFinishState.FAILURE: context.log.error( f"compute_fn() FAILURE with item: {item_name} failed to execute" ) raise Failure() for resources in output_resources_list: for connection in self._connections_by_source.get(item_name, []): connection.receive_resources_from_source(resources) if connection.has_filters(): connection.fetch_database_items() return list(zip(*output_resources_list)), success[0]
def compute_fn(context, inputs): if self.state() == SpineEngineState.USER_STOPPED: context.log.error( f"compute_fn() FAILURE with item: {item_name} stopped by the user" ) raise Failure() context.log.info(f"Item Name: {item_name}") item = self._make_item(item_name, ED.BACKWARD) resources = item.output_resources(ED.BACKWARD) yield Output(value=resources, output_name=f"{ED.BACKWARD}_output")