emile 1 year ago
parent 7ca444571e
commit ec178d9426

Binary file not shown.

@ -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
)

@ -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
},
}

Loading…
Cancel
Save