Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing timeout logic #606

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions tr_sys/tr_ars/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,24 @@ def catch_timeout_async():
now =timezone.now()
logging.info(f'Checking timeout at {now}')
time_threshold = now - timezone.timedelta(minutes=10)
merge_timedelta = timezone.timedelta(minutes=8)
max_time = time_threshold+timezone.timedelta(minutes=5)
max_time = now-timezone.timedelta(minutes=5)
max_time_merged=now-timezone.timedelta(minutes=8)

messages = Message.objects.filter(timestamp__gt=time_threshold,timestamp__lt=max_time, status__in='R').values_list('actor','id','timestamp','updated_at')
messages = Message.objects.filter(timestamp__gt=time_threshold, status__in='R').values_list('actor','id','timestamp','updated_at')
for mesg in messages:
mpk=mesg[0]
id = mesg[1]
actor = Agent.objects.get(pk=mpk)
timestamp=mesg[2]

logging.info(f'actor: {actor} id: {mesg[1]} timestamp: {mesg[2]} updated_at {mesg[3]}')

#exempting parents from timing out
if actor.name == 'ars-default-agent':
continue

elif actor.name == 'ars-ars-agent':
if now - timestamp > merge_timedelta:
if timestamp < max_time_merged:
logging.info('merge_agent pk: %s has been running more than 8 min, setting its code to 598')
message = get_object_or_404(Message.objects.filter(pk=mesg[1]))
message.code = 598
Expand All @@ -214,8 +215,9 @@ def catch_timeout_async():
else:
continue
else:
logging.info(f'for actor: {actor.name}, and pk {str(id)} the status is still "Running" after 5 min, setting code to 598')
message = get_object_or_404(Message.objects.filter(pk=mesg[1]))
message.code = 598
message.status = 'E'
message.save(update_fields=['status','code'])
if timestamp < max_time:
logging.info(f'for actor: {actor.name}, and pk {str(id)} the status is still "Running" after 5 min, setting code to 598')
message = get_object_or_404(Message.objects.filter(pk=mesg[1]))
message.code = 598
message.status = 'E'
message.save(update_fields=['status','code'])