<commit_before>import abc
import logging

import pendulum
from celery.schedules import crontab
from django.utils.functional import cached_property

from share.robot import RobotAppConfig

logger = logging.getLogger(__name__)


class BotAppConfig(RobotAppConfig, metaclass=abc.ABCMeta):

    schedule = crontab(minute=0, hour=0)
    task = 'share.tasks.BotTask'
    description = 'TODO'  # TODO

    @property
    def task_name(self):
        return '{} bot task'.format(self.label)

    @property
    def label(self):
        return self.name.rpartition('bots.')[2]

    @abc.abstractmethod
    def get_bot(self, started_by, last_run=None):
        raise NotImplementedError


class Bot(abc.ABC):

    def __init__(self, config, started_by, last_run=None):
        self.started_by = started_by
        self.config = config
        self._last_run = last_run or 0

    @cached_property
    def last_run(self) -> pendulum.Pendulum:
        from share.models import CeleryProviderTask

        if self._last_run is not None:
            if isinstance(self._last_run, int):
                last_run = pendulum.from_timestamp(self._last_run)
            else:
                last_run = pendulum.parse(self._last_run)
        else:
            logger.debug('Finding last successful job')
            last_run = CeleryProviderTask.objects.filter(
                app_label=self.config.label,
                status=CeleryProviderTask.STATUS.succeeded,
            ).order_by(
                '-timestamp'
            ).values_list('timestamp', flat=True).first()
            if last_run:
                last_run = pendulum.instance(last_run)
            else:
                last_run = pendulum.from_timestamp(0)
            logger.info('Found last job %s', last_run)

        logger.info('Using last run of %s', last_run)
        return last_run

    @abc.abstractmethod
    def run(self):
        raise NotImplementedError
<commit_msg>Un break ES<commit_after>import abc
import logging

import pendulum
from celery.schedules import crontab
from django.utils.functional import cached_property

from share.robot import RobotAppConfig

logger = logging.getLogger(__name__)


class BotAppConfig(RobotAppConfig, metaclass=abc.ABCMeta):

    schedule = crontab(minute=0, hour=0)
    task = 'share.tasks.BotTask'
    description = 'TODO'  # TODO

    @property
    def task_name(self):
        return '{} bot task'.format(self.label)

    @property
    def label(self):
        return self.name.rpartition('bots.')[2]

    @abc.abstractmethod
    def get_bot(self, started_by, last_run=None):
        raise NotImplementedError


class Bot(abc.ABC):

    def __init__(self, config, started_by, last_run=None):
        self.started_by = started_by
        self.config = config
        self._last_run = last_run

    @cached_property
    def last_run(self) -> pendulum.Pendulum:
        from share.models import CeleryProviderTask

        if self._last_run is not None:
            if isinstance(self._last_run, int):
                last_run = pendulum.from_timestamp(self._last_run)
            else:
                last_run = pendulum.parse(self._last_run)
        else:
            logger.debug('Finding last successful job')
            last_run = CeleryProviderTask.objects.filter(
                app_label=self.config.label,
                status=CeleryProviderTask.STATUS.succeeded,
            ).order_by(
                '-timestamp'
            ).values_list('timestamp', flat=True).first()
            if last_run:
                last_run = pendulum.instance(last_run)
            else:
                last_run = pendulum.from_timestamp(0)
            logger.info('Found last job %s', last_run)

        logger.info('Using last run of %s', last_run)
        return last_run

    @abc.abstractmethod
    def run(self):
        raise NotImplementedError

{'fraction_non_alphanumeric': 0.08918848846253564, 'fraction_numerical': 0.00233341975628727, 'mean_word_length': 2.381244522348817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3771547', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1112, 'n_words': 246}