<commit_before>import importlib
import logging

from auto_tasks.base_service import BaseAutoTaskService, NoopTaskService
from auto_tasks.exceptions import RetryableTaskException
from eb_sqs.decorators import task
from eb_sqs.worker.worker_exceptions import MaxRetriesReachedException

logger = logging.getLogger(__name__)


@task()
def _auto_task_wrapper(module_name, class_name, func_name, *args, **kwargs):
    try:
        module = importlib.import_module(module_name)  # import module
        class_ = getattr(module, class_name)  # find class
        instance = class_(auto_task_service=NoopTaskService())  # instantiate class using empty AutoTaskService
        getattr(instance, func_name)(*args, **kwargs)  # invoke method on instance
    except RetryableTaskException as exc:
        try:
            _auto_task_wrapper.retry()
        except MaxRetriesReachedException:
            logger.error('Reached max retries in auto task {}.{}.{} with error: {}'.format(module_name, class_name, func_name, repr(exc)))


class AutoTaskService(BaseAutoTaskService):
    def register_task(self, method, queue_name=None, max_retries=None):
        instance = method.im_self
        class_ = instance.__class__
        func_name = method.func_name

        def _auto_task_wrapper_invoker(*args, **kwargs):
            _auto_task_wrapper.delay(
                class_.__module__,
                class_.__name__,
                func_name,
                *args, queue_name=queue_name, max_retries=max_retries, **kwargs
            )

        setattr(instance, func_name, _auto_task_wrapper_invoker)
<commit_msg>debug code<commit_after>import importlib
import logging

from auto_tasks.base_service import BaseAutoTaskService, NoopTaskService
from auto_tasks.exceptions import RetryableTaskException
from eb_sqs.decorators import task
from eb_sqs.worker.worker_exceptions import MaxRetriesReachedException

logger = logging.getLogger(__name__)


@task()
def _auto_task_wrapper(module_name, class_name, func_name, *args, **kwargs):
    try:
        print('m: {} c: {} f: {}'.format(module_name, class_name, func_name))

        module = importlib.import_module(module_name)  # import module
        class_ = getattr(module, class_name)  # find class
        instance = class_(auto_task_service=NoopTaskService())  # instantiate class using empty AutoTaskService
        getattr(instance, func_name)(*args, **kwargs)  # invoke method on instance
    except RetryableTaskException as exc:
        try:
            _auto_task_wrapper.retry()
        except MaxRetriesReachedException:
            logger.error('Reached max retries in auto task {}.{}.{} with error: {}'.format(module_name, class_name, func_name, repr(exc)))


class AutoTaskService(BaseAutoTaskService):
    def register_task(self, method, queue_name=None, max_retries=None):
        instance = method.im_self
        class_ = instance.__class__
        func_name = method.func_name

        def _auto_task_wrapper_invoker(*args, **kwargs):
            _auto_task_wrapper.delay(
                class_.__module__,
                class_.__name__,
                func_name,
                *args, queue_name=queue_name, max_retries=max_retries, **kwargs
            )

        setattr(instance, func_name, _auto_task_wrapper_invoker)

{'fraction_non_alphanumeric': 0.08328267477203648, 'fraction_numerical': 0.0, 'mean_word_length': 3.4959016393442623, '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': '3474465', 'n_tokens_mistral': 961, 'n_tokens_neox': 941, 'n_words': 209}