<commit_before>from bot.api.api import Api
from bot.multithreading.scheduler import SchedulerApi
from bot.storage import Config, State, Cache


class Action:
    def __init__(self):
        pass

    def get_name(self):
        return self.__class__.__name__

    def setup(self, api: Api, config: Config, state: State, cache: Cache, scheduler: SchedulerApi):
        self.api = api
        self.config = config
        self.state = state
        self.cache = cache
        self.scheduler = scheduler
        self.post_setup()

    def post_setup(self):
        pass

    def process(self, event):
        pass


class ActionGroup(Action):
    def __init__(self, *actions):
        super().__init__()
        self.actions = list(actions)

    def add(self, *actions):
        self.actions.extend(actions)

    def setup(self, *args):
        super().setup(*args)
        self.for_each(lambda action: action.setup(*args))

    def process(self, event):
        self.for_each(lambda action: action.process(event._copy()))

    def for_each(self, func):
        for action in self.actions:
            func(action)


class IntermediateAction(ActionGroup):
    def __init__(self):
        super().__init__()

    def then(self, *next_actions):
        self.add(*next_actions)
        return self

    def _continue(self, event):
        super().process(event)
<commit_msg>Add shutdown callback support to Action<commit_after>from bot.api.api import Api
from bot.multithreading.scheduler import SchedulerApi
from bot.storage import Config, State, Cache


class Action:
    def __init__(self):
        pass

    def get_name(self):
        return self.__class__.__name__

    def setup(self, api: Api, config: Config, state: State, cache: Cache, scheduler: SchedulerApi):
        self.api = api
        self.config = config
        self.state = state
        self.cache = cache
        self.scheduler = scheduler
        self.post_setup()

    def post_setup(self):
        pass

    def process(self, event):
        pass

    def pre_shutdown(self):
        pass

    def shutdown(self):
        self.pre_shutdown()


class ActionGroup(Action):
    def __init__(self, *actions):
        super().__init__()
        self.actions = list(actions)

    def add(self, *actions):
        self.actions.extend(actions)

    def setup(self, *args):
        super().setup(*args)
        self.for_each(lambda action: action.setup(*args))

    def process(self, event):
        self.for_each(lambda action: action.process(event._copy()))

    def shutdown(self):
        self.for_each(lambda action: action.shutdown())
        super().shutdown()

    def for_each(self, func):
        for action in self.actions:
            func(action)


class IntermediateAction(ActionGroup):
    def __init__(self):
        super().__init__()

    def then(self, *next_actions):
        self.add(*next_actions)
        return self

    def _continue(self, event):
        super().process(event)

{'fraction_non_alphanumeric': 0.10792580101180438, 'fraction_numerical': 0.0, 'mean_word_length': 2.56062424969988, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '740158', 'n_tokens_mistral': 883, 'n_tokens_neox': 852, 'n_words': 219}