from ewokscore import Task
import logging
import gc

logger = logging.getLogger(__name__)


class EndTask(
    Task,
    optional_input_names=[
        "detector_name",
        "scan_memory_url",
        "filename_data",
        "scan_nb",
        "index_range_last",
        "loop_nb",
    ],
    output_names=[
        "detector_name",
        "scan_memory_url",
        "filename_data",
        "scan_nb",
        "index_range_last",
        "loop_nb",
    ],
):
    def run(self):
        logger.warning("\n\n\tEndTask. End of the workflow\n")
        self.outputs.detector_name = self.get_input_value("detector_name")
        self.outputs.scan_memory_url = self.get_input_value("scan_memory_url")
        self.outputs.filename_data = self.get_input_value("filename_data")
        self.outputs.scan_nb = self.get_input_value("scan_nb")
        self.outputs.index_range_last = self.get_input_value("index_range_last")
        self.outputs.loop_nb = self.get_input_value("loop_nb")
        gc.collect()
