diff --git a/osinaweb/osinacore/.DS_Store b/osinaweb/osinacore/.DS_Store index 5f6ea1ec..1e846952 100644 Binary files a/osinaweb/osinacore/.DS_Store and b/osinaweb/osinacore/.DS_Store differ diff --git a/osinaweb/osinacore/__pycache__/models.cpython-310.pyc b/osinaweb/osinacore/__pycache__/models.cpython-310.pyc index 36d64359..c61a1bfc 100644 Binary files a/osinaweb/osinacore/__pycache__/models.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/models.cpython-310.pyc differ 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 }, }