From ec178d9426c0d8c19eb2847ce6c67e6ad66e646b Mon Sep 17 00:00:00 2001 From: emile Date: Thu, 21 Mar 2024 12:46:41 +0200 Subject: [PATCH] New --- osinaweb/osinacore/.DS_Store | Bin 10244 -> 10244 bytes .../__pycache__/models.cpython-310.pyc | Bin 11458 -> 11458 bytes osinaweb/osinacore/tasks.py | 36 +++++++++--------- osinaweb/osinaweb/celery.py | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/osinaweb/osinacore/.DS_Store b/osinaweb/osinacore/.DS_Store index 5f6ea1ec78cdd69bf78b4ce2c1a6afeb00f5deb6..1e8469528d28a9eed489334e780e3152a658f912 100644 GIT binary patch delta 43 kcmZn(XbIR5E6QPPXsM%MXlXe4fuO_YrJ_6d(M95!04Y`tZ2$lO delta 43 kcmZn(XbIR5E6QPHX`rKEWMnw`fuO_YrJ_6d(M95!04Njt<8 diff --git a/osinaweb/osinacore/__pycache__/models.cpython-310.pyc b/osinaweb/osinacore/__pycache__/models.cpython-310.pyc index 36d64359c937cc088ccc42de5baa03745f1e3e0a..c61a1bfccc205cb0c2eaa239d7100409e3856de4 100644 GIT binary patch delta 20 acmX>Uc_@-QpO=@50SHWZ|7_&mt^)u)kp-~; delta 20 acmX>Uc_@-QpO=@50SNxS`n{2RyAA+IIR{n% diff --git a/osinaweb/osinacore/tasks.py b/osinaweb/osinacore/tasks.py index 1b1a2ac4..91bd66c6 100644 --- a/osinaweb/osinacore/tasks.py +++ b/osinaweb/osinacore/tasks.py @@ -5,28 +5,26 @@ from django.db.models import Q @shared_task def set_offline(): - print('Hello') all_staff_profiles = StaffProfile.objects.all() - staff_without_working_points = all_staff_profiles.exclude( - Q(task__point__status='Working On') - ) + for staff_profile in all_staff_profiles: + last_working_point_activity = PointActivity.objects.filter( + point__status='Working On', + point__task__assigned_to=staff_profile.user, + ).order_by('-end_time').first() - users_without_working_points = [staff_profile.user for staff_profile in staff_without_working_points] - print(users_without_working_points) - - # Create a new connection record for each user with status set to 'Offline' - for user in users_without_working_points: - last_connection = Connection.objects.filter(user=user).order_by('-date').first() - if last_connection.status != 'Offline': - Connection.objects.create( - status='Offline', - date=timezone.now(), - user=user - ) - new_status = Status.objects.create( + if last_working_point_activity and last_working_point_activity.end_time <= datetime.now() - timedelta(minutes=10): + user = staff_profile.user + last_connection = Connection.objects.filter(user=user).order_by('-date').first() + if last_connection is None or last_connection.status != 'Offline': + Connection.objects.create( + status='Offline', + date=datetime.now(), + user=user + ) + Status.objects.create( text='I am now offline!', - date=datetime.now().date(), # Getting the current date - time=datetime.now().strftime('%I:%M %p'), + date=datetime.now().date(), + time=datetime.now().strftime('%I:%M %p'), staff=user.staffprofile ) \ No newline at end of file diff --git a/osinaweb/osinaweb/celery.py b/osinaweb/osinaweb/celery.py index 3cf1c450..ee4c6152 100644 --- a/osinaweb/osinaweb/celery.py +++ b/osinaweb/osinaweb/celery.py @@ -18,6 +18,6 @@ celery_app.autodiscover_tasks() celery_app.conf.beat_schedule = { 'set-offline-every-minute': { 'task': 'osinacore.tasks.set_offline', # Assuming your task is in tasks.py in your_app - 'schedule': crontab(minute='*/15'), # Run every minute + 'schedule': crontab(second='*'), # Run every secon }, }