Compare commits
No commits in common. "2d16029ed7c013117199d6d3c75774975ac4de5c" and "3d7d4289145d96c9eaf4d47e7294599cb59d9d2e" have entirely different histories.
2d16029ed7
...
3d7d428914
@ -9,13 +9,3 @@ def ensure_scheduled(name: str, func, **kwargs):
|
||||
**kwargs,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def q_task_group(task_group: str):
|
||||
"""Decorator to more cleanly add `q_task_group` to a function"""
|
||||
|
||||
def inner(func):
|
||||
func.q_task_group = task_group
|
||||
return func
|
||||
|
||||
return inner
|
||||
|
@ -10,7 +10,7 @@ def post_migrate_callback(sender, **kwargs):
|
||||
from .tasks.scrapehidevents import q_getMessagesAllDoors
|
||||
|
||||
ensure_scheduled(
|
||||
q_getMessagesAllDoors.q_task_group,
|
||||
"Fetch HID Events",
|
||||
q_getMessagesAllDoors,
|
||||
schedule_type=Schedule.MINUTES,
|
||||
minutes=15,
|
||||
|
@ -5,7 +5,6 @@ from django.utils import timezone
|
||||
|
||||
from django_q.tasks import async_task
|
||||
|
||||
from cmsmanage.django_q2_helper import q_task_group
|
||||
from doorcontrol.models import Door, HIDEvent
|
||||
|
||||
|
||||
@ -35,7 +34,6 @@ def getMessages(door: Door):
|
||||
}
|
||||
|
||||
|
||||
@q_task_group("Fetch HID Events")
|
||||
def q_getMessagesAllDoors():
|
||||
# TODO: this should probably use async_iter
|
||||
for door in Door.objects.all():
|
||||
|
@ -45,7 +45,7 @@ class BaseMembershipWorksAdmin(DjangoObjectActions, ReadOnlyAdmin):
|
||||
if tool_name == "refresh_membershipworks_data":
|
||||
try:
|
||||
last_run_time = naturaltime(
|
||||
Task.objects.filter(group=scrape_membershipworks.q_task_group)
|
||||
Task.objects.filter(group="Scrape Data from MembershipWorks")
|
||||
.values_list("started", flat=True)
|
||||
.latest("started")
|
||||
)
|
||||
@ -56,7 +56,7 @@ class BaseMembershipWorksAdmin(DjangoObjectActions, ReadOnlyAdmin):
|
||||
|
||||
@action
|
||||
def refresh_membershipworks_data(self, request, obj):
|
||||
async_task(scrape_membershipworks, group=scrape_membershipworks.q_task_group)
|
||||
async_task(scrape_membershipworks, group="Scrape Data from MembershipWorks")
|
||||
self.message_user(
|
||||
request,
|
||||
"Queued refresh, please wait a few seconds/minutes then refresh the page",
|
||||
@ -146,7 +146,7 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin):
|
||||
else:
|
||||
fields.append(field.name)
|
||||
fields.insert(fields.index("end") + 1, "duration")
|
||||
fields.append("_details_timestamp")
|
||||
fields.append("details_timestamp")
|
||||
return fields
|
||||
|
||||
@admin.display(ordering="duration")
|
||||
@ -160,10 +160,6 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin):
|
||||
obj.url,
|
||||
)
|
||||
|
||||
@admin.display(description="Last details fetch")
|
||||
def _details_timestamp(self, obj):
|
||||
return naturaltime(obj.details_timestamp)
|
||||
|
||||
@takes_instance_or_queryset
|
||||
def fetch_details(self, request, queryset):
|
||||
scrape_event_details(queryset)
|
||||
|
@ -11,19 +11,19 @@ def post_migrate_callback(sender, **kwargs):
|
||||
from .tasks.ucsAccounts import sync_accounts
|
||||
|
||||
ensure_scheduled(
|
||||
scrape_membershipworks.q_task_group,
|
||||
"Scrape MembershipWorks Data",
|
||||
scrape_membershipworks,
|
||||
schedule_type=Schedule.HOURLY,
|
||||
)
|
||||
|
||||
ensure_scheduled(
|
||||
scrape_events.q_task_group,
|
||||
"Scrape MembershipWorks Events",
|
||||
scrape_events,
|
||||
schedule_type=Schedule.HOURLY,
|
||||
)
|
||||
|
||||
ensure_scheduled(
|
||||
sync_accounts.q_task_group,
|
||||
"Sync UCS Accounts",
|
||||
sync_accounts,
|
||||
schedule_type=Schedule.MINUTES,
|
||||
minutes=15,
|
||||
|
@ -511,14 +511,6 @@ class EventExtManager(models.Manager["EventExt"]):
|
||||
* F("count"),
|
||||
models.DurationField(),
|
||||
),
|
||||
# TODO: this could be a GeneratedField, but that
|
||||
# currently breaks saving when the primary key is
|
||||
# provided (Django 5.0.1)
|
||||
details_timestamp=Func(
|
||||
Func(F("details___ts"), function="FROM_UNIXTIME"),
|
||||
template="CONVERT_TZ(%(expressions)s, @@session.time_zone, 'UTC')",
|
||||
output_field=models.DateTimeField(),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
@ -542,6 +534,14 @@ class EventExt(Event):
|
||||
max_digits=13, decimal_places=4, default=0
|
||||
)
|
||||
details = models.JSONField(null=True, blank=True)
|
||||
details_timestamp = models.GeneratedField(
|
||||
expression=Func(
|
||||
Func(F("details___ts"), function="FROM_UNIXTIME"),
|
||||
template="CONVERT_TZ(%(expressions)s, @@session.time_zone, 'UTC')",
|
||||
),
|
||||
output_field=models.DateTimeField(),
|
||||
db_persist=False,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "event"
|
||||
|
@ -5,7 +5,6 @@ from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.db.models import QuerySet
|
||||
|
||||
from cmsmanage.django_q2_helper import q_task_group
|
||||
from membershipworks.membershipworks_api import FieldType, MembershipWorks
|
||||
from membershipworks.models import (
|
||||
Event,
|
||||
@ -90,7 +89,6 @@ def scrape_transactions(membershipworks: MembershipWorks):
|
||||
Transaction.from_api_dict(csv_transaction).save()
|
||||
|
||||
|
||||
@q_task_group("Scrape MembershipWorks Data")
|
||||
@transaction.atomic
|
||||
def scrape_membershipworks(*args, **options):
|
||||
membershipworks = MembershipWorks()
|
||||
@ -113,7 +111,6 @@ def scrape_event_details(queryset: QuerySet[EventExt]):
|
||||
event.save()
|
||||
|
||||
|
||||
@q_task_group("Scrape MembershipWorks Events")
|
||||
def scrape_events():
|
||||
membershipworks = MembershipWorks()
|
||||
membershipworks.login(
|
||||
|
@ -8,7 +8,6 @@ from django.conf import settings
|
||||
from udm_rest_client.exceptions import NoObject, UdmError
|
||||
from udm_rest_client.udm import UDM
|
||||
|
||||
from cmsmanage.django_q2_helper import q_task_group
|
||||
from membershipworks.models import Flag, Member
|
||||
|
||||
USER_BASE = "cn=users,dc=sawtooth,dc=claremontmakerspace,dc=org"
|
||||
@ -133,6 +132,5 @@ async def async_accounts():
|
||||
await sync_member(user_mod, member)
|
||||
|
||||
|
||||
@q_task_group("Sync UCS Accounts")
|
||||
def sync_accounts():
|
||||
asyncio.run(async_accounts())
|
||||
|
Loading…
Reference in New Issue
Block a user