Skip to content

Commit a7fa827

Browse files
authored
Update status on task timeout (#2454)
1 parent d1c9cb1 commit a7fa827

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

mobsf/StaticAnalyzer/views/common/async_task.py

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
timedelta,
55
)
66

7+
from django.dispatch import receiver
78
from django.utils import timezone
89
from django.shortcuts import render
910
from django.conf import settings
@@ -14,6 +15,7 @@
1415
from django.views.decorators.http import require_http_methods
1516

1617
from django_q.tasks import async_task
18+
from django_q.signals import post_execute
1719

1820
from mobsf.StaticAnalyzer.models import (
1921
EnqueuedTask,
@@ -30,6 +32,19 @@
3032
logger = logging.getLogger(__name__)
3133

3234

35+
@receiver(post_execute)
36+
def detect_timeout(sender, task, **kwargs):
37+
"""Detect scan task timeout."""
38+
if 'Task exceeded maximum timeout' in task['result']:
39+
task_id = task['id']
40+
EnqueuedTask.objects.filter(task_id=task_id).update(
41+
app_name='Failed',
42+
completed_at=timezone.now(),
43+
status='Scan Timeout',
44+
)
45+
logger.error('Task %s exceeded maximum timeout', task_id)
46+
47+
3348
def async_analysis(checksum, app_name, func, *args):
3449
"""Async Analysis Task."""
3550
# Check if the task is already completed

0 commit comments

Comments
 (0)