Compare commits
3 Commits
6408748c3f
...
8c48514c04
Author | SHA1 | Date | |
---|---|---|---|
8c48514c04 | |||
300397b021 | |||
a90cd39612 |
20
cmsmanage/django_q2_admin_email_reporter.py
Normal file
20
cmsmanage/django_q2_admin_email_reporter.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from django.views.debug import ExceptionReporter
|
||||||
|
from django.core import mail
|
||||||
|
|
||||||
|
|
||||||
|
class AdminEmailReporter:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def report(self):
|
||||||
|
reporter = ExceptionReporter(None, *sys.exc_info())
|
||||||
|
message = f"Failed to run task\n{reporter.get_traceback_text()}"
|
||||||
|
html_message = reporter.get_traceback_html()
|
||||||
|
mail.mail_admins(
|
||||||
|
"Django Q task failed",
|
||||||
|
message,
|
||||||
|
# fail_silently=True,
|
||||||
|
html_message=html_message,
|
||||||
|
)
|
@ -1,5 +1,3 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
from django_q.models import Schedule
|
from django_q.models import Schedule
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,6 +124,7 @@ Q_CLUSTER = {
|
|||||||
"retry": 60 * 6,
|
"retry": 60 * 6,
|
||||||
"timeout": 60 * 5,
|
"timeout": 60 * 5,
|
||||||
"catch_up": False,
|
"catch_up": False,
|
||||||
|
"error_reporter": {"admin_email": {}},
|
||||||
"ALT_CLUSTERS": {
|
"ALT_CLUSTERS": {
|
||||||
"internal": {
|
"internal": {
|
||||||
"retry": 60 * 60,
|
"retry": 60 * 60,
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.db.models.signals import post_migrate
|
||||||
|
|
||||||
|
|
||||||
|
def post_migrate_callback(sender, **kwargs):
|
||||||
|
from .tasks.scrapehidevents import schedule_tasks
|
||||||
|
|
||||||
|
schedule_tasks()
|
||||||
|
|
||||||
|
|
||||||
class DoorControlConfig(AppConfig):
|
class DoorControlConfig(AppConfig):
|
||||||
@ -7,6 +14,4 @@ class DoorControlConfig(AppConfig):
|
|||||||
verbose_name = "Door Control"
|
verbose_name = "Door Control"
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
from .tasks.scrapehidevents import schedule_tasks
|
post_migrate.connect(post_migrate_callback, sender=self)
|
||||||
|
|
||||||
schedule_tasks()
|
|
||||||
|
@ -1,15 +1,26 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import ExpressionWrapper, F, Func, Q
|
from django.db.models import ExpressionWrapper, F, Func, Q
|
||||||
from django.db.models.functions import Mod
|
from django.db.models.functions import Mod
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from .hid.DoorController import DoorController
|
||||||
|
|
||||||
|
|
||||||
class Door(models.Model):
|
class Door(models.Model):
|
||||||
name = models.CharField(max_length=64, unique=True)
|
name = models.CharField(max_length=64, unique=True)
|
||||||
ip = models.GenericIPAddressField(protocol="IPv4")
|
ip = models.GenericIPAddressField(protocol="IPv4")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def controller(self) -> DoorController:
|
||||||
|
return DoorController(
|
||||||
|
self.ip,
|
||||||
|
settings.HID_DOOR_USERNAME,
|
||||||
|
settings.HID_DOOR_PASSWORD,
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
@ -9,7 +8,6 @@ from django_q.models import Schedule
|
|||||||
|
|
||||||
from cmsmanage.django_q2_helper import ensure_scheduled
|
from cmsmanage.django_q2_helper import ensure_scheduled
|
||||||
from doorcontrol.models import Door, HIDEvent
|
from doorcontrol.models import Door, HIDEvent
|
||||||
from doorcontrol.hid.DoorController import DoorController
|
|
||||||
|
|
||||||
|
|
||||||
@transaction.atomic()
|
@transaction.atomic()
|
||||||
@ -20,13 +18,7 @@ def getMessages(door: Door):
|
|||||||
else:
|
else:
|
||||||
last_ts = datetime(2010, 1, 1)
|
last_ts = datetime(2010, 1, 1)
|
||||||
|
|
||||||
door_controller = DoorController(
|
for events_page in door.controller.get_events(last_ts):
|
||||||
door.ip,
|
|
||||||
settings.HID_DOOR_USERNAME,
|
|
||||||
settings.HID_DOOR_PASSWORD,
|
|
||||||
)
|
|
||||||
|
|
||||||
for events_page in door_controller.get_events(last_ts):
|
|
||||||
print(f"Importing {len(events_page)} events for {door.name}")
|
print(f"Importing {len(events_page)} events for {door.name}")
|
||||||
HIDEvent.objects.bulk_create(
|
HIDEvent.objects.bulk_create(
|
||||||
(HIDEvent.from_xml_attributes(door, event.attrib) for event in events_page),
|
(HIDEvent.from_xml_attributes(door, event.attrib) for event in events_page),
|
||||||
|
@ -35,6 +35,9 @@ server = [
|
|||||||
"setuptools~=68.2",
|
"setuptools~=68.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[project.entry-points."djangoq.errorreporters"]
|
||||||
|
admin_email = "cmsmanage.django_q2_admin_email_reporter:AdminEmailReporter"
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
line-length = 88
|
line-length = 88
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user