# Path: tg_utils/health_check/checks/celery_beat/backends.py
# TIMEOUT = getattr(settings, 'HEALTH_CHECK', {}).get('CELERY_BEAT_CHECK_INTERVAL', 60)
# 
# Path: tg_utils/health_check/checks/celery_beat/tasks.py
# @shared_task(ignore_result=False)
# def timestamp_task():
#     # timeout=None causes value to be stored forever
#     cache.set(CACHE_KEY, datetime.now(), timeout=None)


import importlib
from django.apps import AppConfig
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from health_check.plugins import plugin_dir
from tg_utils.health_check.checks.celery_beat.backends import TIMEOUT
from tg_utils.health_check.checks.celery_beat.tasks import timestamp_task
        from .backends import CeleryBeatHealthCheck




class HealthCheckConfig(AppConfig):
    name = 'tg_utils.health_check.checks.celery_beat'

    def ready(self):

        cls = getattr(settings, 'HEALTH_CHECK', {}).get('CELERY_APP', None)
        if cls is None:
            raise ImproperlyConfigured(
                "Set HEALTH_CHECK['CELERY_APP'] to point to celery app instance in your settings to use celery "
                "beat health-check (example value: 'my_project.celery.app')"
            )

        module_name, class_name = cls.rsplit(".", 1)
        app_module = importlib.import_module(module_name)

        # Set initial timestamp not to fail the health-check before it runs for the first time
        # Don't use apply_async - otherwise, the whole initialisation will fail if celery fails
        try:
            timestamp_task()

            getattr(app_module, class_name).add_periodic_task(

# Path: tg_utils/health_check/checks/celery_beat/backends.py
# TIMEOUT = getattr(settings, 'HEALTH_CHECK', {}).get('CELERY_BEAT_CHECK_INTERVAL', 60)
# 
# Path: tg_utils/health_check/checks/celery_beat/tasks.py
# @shared_task(ignore_result=False)
# def timestamp_task():
#     # timeout=None causes value to be stored forever
#     cache.set(CACHE_KEY, datetime.now(), timeout=None)


# Path: tg_utils/health_check/checks/celery_beat/apps.py
import importlib
from django.apps import AppConfig
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from health_check.plugins import plugin_dir
from tg_utils.health_check.checks.celery_beat.backends import TIMEOUT
from tg_utils.health_check.checks.celery_beat.tasks import timestamp_task
        from .backends import CeleryBeatHealthCheck





class HealthCheckConfig(AppConfig):
    name = 'tg_utils.health_check.checks.celery_beat'

    def ready(self):

        cls = getattr(settings, 'HEALTH_CHECK', {}).get('CELERY_APP', None)
        if cls is None:
            raise ImproperlyConfigured(
                "Set HEALTH_CHECK['CELERY_APP'] to point to celery app instance in your settings to use celery "
                "beat health-check (example value: 'my_project.celery.app')"
            )

        module_name, class_name = cls.rsplit(".", 1)
        app_module = importlib.import_module(module_name)

        # Set initial timestamp not to fail the health-check before it runs for the first time
        # Don't use apply_async - otherwise, the whole initialisation will fail if celery fails
        try:
            timestamp_task()

            getattr(app_module, class_name).add_periodic_task(

                TIMEOUT, timestamp_task.s(), name='Celery health check beat',