backend.lib.preset
Queue a series of processors at once via a preset
1""" 2Queue a series of processors at once via a preset 3""" 4import abc 5from backend.lib.processor import BasicProcessor 6 7from common.lib.dataset import DataSet 8 9 10class ProcessorPreset(BasicProcessor): 11 """ 12 Processor preset 13 """ 14 def process(self): 15 """ 16 ALL PRESETS MUST PREPEND 'preset-' TO THEIR TYPE. 17 18 This queues a series of post-processors to run in sequence, with an 19 overarching dataset to which the results of the last processor in the 20 sequence are copied. The processor pipeline is then attached to the 21 overarching dataset so it is clear that all processors were run as part 22 of that particular preset. 23 """ 24 pipeline = self.get_processor_pipeline() 25 26 # make sure the last item in the pipeline copies to the preset's dataset 27 # also make sure there is always a "parameters" key 28 pipeline = [{"parameters": {}, **p} for p in pipeline.copy()] 29 30 pipeline[-1]["parameters"]["attach_to"] = self.dataset.key 31 32 # map the linear pipeline to a nested processor parameter set 33 while len(pipeline) > 1: 34 last = pipeline.pop() 35 pipeline[-1]["parameters"]["next"] = [last] 36 37 analysis_pipeline = DataSet(parameters=pipeline[0]["parameters"], type=pipeline[0]["type"], db=self.db, 38 parent=self.dataset.key, modules=self.modules) 39 40 # this starts the pipeline 41 self.queue.add_job(pipeline[0]["type"], remote_id=analysis_pipeline.key) 42 43 def after_process(self): 44 """ 45 Run after processing 46 47 In this case, this is run immediately after the underlying analyses 48 have been queued. This overrides the default behaviour which finishes 49 the DataSet after processing; in this case, it is left 'open' until it 50 is finished by the last underlying analysis. 51 """ 52 self.dataset.update_status("Awaiting completion of underlying analyses...") 53 self.job.finish() 54 55 @abc.abstractmethod 56 def get_processor_pipeline(self): 57 """ 58 Preset pipeline definition 59 60 Should return a list of dictionaries, each dictionary having a `type` 61 key with the processor type ID and a `parameters` key with the 62 processor parameters. The order of the list is the order in which the 63 processors are run. Compatibility of processors in the list is not 64 checked. 65 66 :return list: Processor pipeline definition 67 """ 68 pass
11class ProcessorPreset(BasicProcessor): 12 """ 13 Processor preset 14 """ 15 def process(self): 16 """ 17 ALL PRESETS MUST PREPEND 'preset-' TO THEIR TYPE. 18 19 This queues a series of post-processors to run in sequence, with an 20 overarching dataset to which the results of the last processor in the 21 sequence are copied. The processor pipeline is then attached to the 22 overarching dataset so it is clear that all processors were run as part 23 of that particular preset. 24 """ 25 pipeline = self.get_processor_pipeline() 26 27 # make sure the last item in the pipeline copies to the preset's dataset 28 # also make sure there is always a "parameters" key 29 pipeline = [{"parameters": {}, **p} for p in pipeline.copy()] 30 31 pipeline[-1]["parameters"]["attach_to"] = self.dataset.key 32 33 # map the linear pipeline to a nested processor parameter set 34 while len(pipeline) > 1: 35 last = pipeline.pop() 36 pipeline[-1]["parameters"]["next"] = [last] 37 38 analysis_pipeline = DataSet(parameters=pipeline[0]["parameters"], type=pipeline[0]["type"], db=self.db, 39 parent=self.dataset.key, modules=self.modules) 40 41 # this starts the pipeline 42 self.queue.add_job(pipeline[0]["type"], remote_id=analysis_pipeline.key) 43 44 def after_process(self): 45 """ 46 Run after processing 47 48 In this case, this is run immediately after the underlying analyses 49 have been queued. This overrides the default behaviour which finishes 50 the DataSet after processing; in this case, it is left 'open' until it 51 is finished by the last underlying analysis. 52 """ 53 self.dataset.update_status("Awaiting completion of underlying analyses...") 54 self.job.finish() 55 56 @abc.abstractmethod 57 def get_processor_pipeline(self): 58 """ 59 Preset pipeline definition 60 61 Should return a list of dictionaries, each dictionary having a `type` 62 key with the processor type ID and a `parameters` key with the 63 processor parameters. The order of the list is the order in which the 64 processors are run. Compatibility of processors in the list is not 65 checked. 66 67 :return list: Processor pipeline definition 68 """ 69 pass
Processor preset
15 def process(self): 16 """ 17 ALL PRESETS MUST PREPEND 'preset-' TO THEIR TYPE. 18 19 This queues a series of post-processors to run in sequence, with an 20 overarching dataset to which the results of the last processor in the 21 sequence are copied. The processor pipeline is then attached to the 22 overarching dataset so it is clear that all processors were run as part 23 of that particular preset. 24 """ 25 pipeline = self.get_processor_pipeline() 26 27 # make sure the last item in the pipeline copies to the preset's dataset 28 # also make sure there is always a "parameters" key 29 pipeline = [{"parameters": {}, **p} for p in pipeline.copy()] 30 31 pipeline[-1]["parameters"]["attach_to"] = self.dataset.key 32 33 # map the linear pipeline to a nested processor parameter set 34 while len(pipeline) > 1: 35 last = pipeline.pop() 36 pipeline[-1]["parameters"]["next"] = [last] 37 38 analysis_pipeline = DataSet(parameters=pipeline[0]["parameters"], type=pipeline[0]["type"], db=self.db, 39 parent=self.dataset.key, modules=self.modules) 40 41 # this starts the pipeline 42 self.queue.add_job(pipeline[0]["type"], remote_id=analysis_pipeline.key)
ALL PRESETS MUST PREPEND 'preset-' TO THEIR TYPE.
This queues a series of post-processors to run in sequence, with an overarching dataset to which the results of the last processor in the sequence are copied. The processor pipeline is then attached to the overarching dataset so it is clear that all processors were run as part of that particular preset.
44 def after_process(self): 45 """ 46 Run after processing 47 48 In this case, this is run immediately after the underlying analyses 49 have been queued. This overrides the default behaviour which finishes 50 the DataSet after processing; in this case, it is left 'open' until it 51 is finished by the last underlying analysis. 52 """ 53 self.dataset.update_status("Awaiting completion of underlying analyses...") 54 self.job.finish()
Run after processing
In this case, this is run immediately after the underlying analyses have been queued. This overrides the default behaviour which finishes the DataSet after processing; in this case, it is left 'open' until it is finished by the last underlying analysis.
56 @abc.abstractmethod 57 def get_processor_pipeline(self): 58 """ 59 Preset pipeline definition 60 61 Should return a list of dictionaries, each dictionary having a `type` 62 key with the processor type ID and a `parameters` key with the 63 processor parameters. The order of the list is the order in which the 64 processors are run. Compatibility of processors in the list is not 65 checked. 66 67 :return list: Processor pipeline definition 68 """ 69 pass
Preset pipeline definition
Should return a list of dictionaries, each dictionary having a type
key with the processor type ID and a parameters
key with the
processor parameters. The order of the list is the order in which the
processors are run. Compatibility of processors in the list is not
checked.
Returns
Processor pipeline definition
Inherited Members
- backend.lib.worker.BasicWorker
- BasicWorker
- type
- max_workers
- INTERRUPT_NONE
- INTERRUPT_RETRY
- INTERRUPT_CANCEL
- queue
- log
- manager
- interrupted
- modules
- init_time
- name
- run
- clean_up
- request_interrupt
- is_4cat_class
- backend.lib.processor.BasicProcessor
- db
- job
- dataset
- owner
- source_dataset
- source_file
- description
- category
- extension
- config
- is_running_in_preset
- filepath
- work
- remove_files
- abort
- add_field_to_parent
- iterate_archive_contents
- unpack_archive_contents
- extract_archived_file_by_name
- write_csv_items_and_finish
- write_archive_and_finish
- create_standalone
- map_item_method_available
- get_mapped_item
- is_filter
- get_options
- get_status
- is_top_dataset
- is_from_collector
- get_extension
- is_rankable
- exclude_followup_processors
- is_4cat_processor