Skip to content

Commit

Permalink
Adds a system check for validating the Celery entrypoint (#254)
Browse files Browse the repository at this point in the history
* Adds system check for validating the Celery entrypoint

* Docstring updates.
  • Loading branch information
djperrefort authored Apr 19, 2024
1 parent 693ba78 commit 24b37a3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions keystone_api/apps/scheduler/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Application configuration and initialization logic.
Subclasses of the Django `AppConfig` class are automatically loaded by Django
and used to initialize the parent application. This includes encapsulating
startup tasks and configuring how the application integrates with the framework.
"""

from django.apps import AppConfig
from django.core.checks import register

from .checks import *


class SchedulerConfig(AppConfig):
"""Configure the parent application"""

name = 'apps.scheduler'

def ready(self):
"""Executed as soon as the Django application registry is fully populated."""

register(check_celery_is_importable)
32 changes: 32 additions & 0 deletions keystone_api/apps/scheduler/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""System checks for verifying proper application configuration.
System checks are used to report configuration errors in the parent
application. See the `apps.py` file for their registration with the
Django System Checks framework.
"""

from django.core.checks import Error

import keystone_api

__all__ = ['check_celery_is_importable']


def check_celery_is_importable(app_configs, **kwargs):
"""Check the `` variable is importable from the top level package"""

errors = []
try:
from keystone_api import celery_app

except ImportError:
errors.append(
Error(
"missing `celery_app` variable",
hint="Make sure the `celery_app` variable is importable from the top level package.",
id="apps.scheduler.E001",
obj=keystone_api
)
)

return errors

0 comments on commit 24b37a3

Please sign in to comment.