Fixes for background worker process

- To determine if worker is running, look for *any* successful task, not just heartbeat
- Heartbeat rate increased to 5 minute intervals
- Small adjustments to django_q settings

Ref: https://github.com/inventree/InvenTree/issues/3921
This commit is contained in:
Oliver 2022-11-12 09:32:51 +11:00
parent 6eeb983f1d
commit cb26003b92
3 changed files with 8 additions and 5 deletions

View File

@ -564,12 +564,16 @@ else:
# django-q background worker configuration
Q_CLUSTER = {
'name': 'InvenTree',
'label': 'Background Tasks',
'workers': int(get_setting('INVENTREE_BACKGROUND_WORKERS', 'background.workers', 4)),
'timeout': int(get_setting('INVENTREE_BACKGROUND_TIMEOUT', 'background.timeout', 90)),
'retry': 120,
'max_attempts': 5,
'queue_limit': 50,
'catch_up': False,
'bulk': 10,
'orm': 'default',
'cache': 'default',
'sync': False,
}

View File

@ -26,15 +26,14 @@ def is_worker_running(**kwargs):
"""
Sometimes Stat.get_all() returns [].
In this case we have the 'heartbeat' task running every 15 minutes.
Check to see if we have a result within the last 20 minutes
In this case we have the 'heartbeat' task running every 5 minutes.
Check to see if we have any successful result within the last 10 minutes
"""
now = timezone.now()
past = now - timedelta(minutes=20)
past = now - timedelta(minutes=10)
results = Success.objects.filter(
func='InvenTree.tasks.heartbeat',
started__gte=past
)

View File

@ -200,7 +200,7 @@ def scheduled_task(interval: str, minutes: int = None, tasklist: TaskRegister =
return _task_wrapper
@scheduled_task(ScheduledTask.MINUTES, 15)
@scheduled_task(ScheduledTask.MINUTES, 5)
def heartbeat():
"""Simple task which runs at 5 minute intervals, so we can determine that the background worker is actually running.