• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

inventree / InvenTree / 8604849533

08 Apr 2024 06:20PM CUT coverage: 78.857%. First build
8604849533

Pull #6981

github

web-flow
Merge 3d6fa4389 into 4adce85ef
Pull Request #6981: Bump djangorestframework from 3.14.0 to 3.15.1 in /src/backend

19152 of 24287 relevant lines covered (78.86%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

3.23
/src/backend/InvenTree/InvenTree/status.py
1
"""Provides system status functionality checks."""
2
# -*- coding: utf-8 -*-
3

4
import logging
5
from datetime import timedelta
6

7
from django.utils import timezone
8
from django.utils.translation import gettext_lazy as _
9

10
from django_q.models import Success
11
from django_q.status import Stat
12

13
import InvenTree.email
14
import InvenTree.ready
15

16
logger = logging.getLogger('inventree')
17

18

19
def is_worker_running(**kwargs):
20
    """Return True if the background worker process is operational."""
21
    clusters = Stat.get_all()
×
22

23
    if len(clusters) > 0:
×
24
        # TODO - Introspect on any cluster information
25
        return True
×
26

27
    """
×
28
    Sometimes Stat.get_all() returns [].
×
29
    In this case we have the 'heartbeat' task running every 5 minutes.
×
30
    Check to see if we have any successful result within the last 10 minutes
×
31
    """
×
32

33
    now = timezone.now()
×
34
    past = now - timedelta(minutes=10)
×
35

36
    results = Success.objects.filter(started__gte=past)
×
37

38
    # If any results are returned, then the background worker is running!
39
    try:
×
40
        result = results.exists()
×
41
    except Exception:
×
42
        # We may throw an exception if the database is not ready,
43
        # or if the django_q table is not yet created (i.e. in CI testing)
44
        result = False
×
45

46
    return result
×
47

48

49
def check_system_health(**kwargs):
1✔
50
    """Check that the InvenTree system is running OK.
51

52
    Returns True if all system checks pass.
53
    """
54
    result = True
×
55

56
    if InvenTree.ready.isInTestMode():
×
57
        # Do not perform further checks if we are running unit tests
58
        return False
×
59

60
    if InvenTree.ready.isImportingData():
×
61
        # Do not perform further checks if we are importing data
62
        return False
×
63

64
    if not is_worker_running(**kwargs):  # pragma: no cover
×
65
        result = False
×
66
        logger.warning(_('Background worker check failed'))
×
67

68
    if not InvenTree.email.is_email_configured():  # pragma: no cover
×
69
        result = False
×
70
        logger.warning(_('Email backend not configured'))
×
71

72
    if not result:  # pragma: no cover
×
73
        logger.warning(_('InvenTree system health checks failed'))
×
74

75
    return result
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc