emile 1 year ago
parent 7ca444571e
commit ec178d9426

Binary file not shown.

@ -5,28 +5,26 @@ from django.db.models import Q
@shared_task @shared_task
def set_offline(): def set_offline():
print('Hello')
all_staff_profiles = StaffProfile.objects.all() all_staff_profiles = StaffProfile.objects.all()
staff_without_working_points = all_staff_profiles.exclude( for staff_profile in all_staff_profiles:
Q(task__point__status='Working On') 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] if last_working_point_activity and last_working_point_activity.end_time <= datetime.now() - timedelta(minutes=10):
print(users_without_working_points) user = staff_profile.user
last_connection = Connection.objects.filter(user=user).order_by('-date').first()
# Create a new connection record for each user with status set to 'Offline' if last_connection is None or last_connection.status != 'Offline':
for user in users_without_working_points: Connection.objects.create(
last_connection = Connection.objects.filter(user=user).order_by('-date').first() status='Offline',
if last_connection.status != 'Offline': date=datetime.now(),
Connection.objects.create( user=user
status='Offline', )
date=timezone.now(), Status.objects.create(
user=user
)
new_status = Status.objects.create(
text='I am now offline!', text='I am now offline!',
date=datetime.now().date(), # Getting the current date date=datetime.now().date(),
time=datetime.now().strftime('%I:%M %p'), time=datetime.now().strftime('%I:%M %p'),
staff=user.staffprofile staff=user.staffprofile
) )

@ -18,6 +18,6 @@ celery_app.autodiscover_tasks()
celery_app.conf.beat_schedule = { celery_app.conf.beat_schedule = {
'set-offline-every-minute': { 'set-offline-every-minute': {
'task': 'osinacore.tasks.set_offline', # Assuming your task is in tasks.py in your_app '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