Run exchange rate updated as task if worker cluster is running

This commit is contained in:
eeintech 2021-07-22 15:55:17 -04:00
parent 2bf7b61668
commit 9b542ed23f

View File

@ -27,6 +27,7 @@ from stock.models import StockLocation, StockItem
from common.models import InvenTreeSetting, ColorTheme from common.models import InvenTreeSetting, ColorTheme
from users.models import check_user_role, RuleSet from users.models import check_user_role, RuleSet
import InvenTree.status
import InvenTree.tasks import InvenTree.tasks
from .forms import DeleteForm, EditUserForm, SetPasswordForm from .forms import DeleteForm, EditUserForm, SetPasswordForm
@ -802,8 +803,17 @@ class CurrencyRefreshView(RedirectView):
On a POST request we will attempt to refresh the exchange rates On a POST request we will attempt to refresh the exchange rates
""" """
# Will block for a little bit # Define associated task
InvenTree.tasks.update_exchange_rates() task_name = 'InvenTree.tasks.update_exchange_rates'
if InvenTree.status.is_worker_running():
# Running as task
InvenTree.tasks.offload_task(task_name)
else:
# Retrieve function from task name
_func = eval(task_name)
# Run it: will block for a little bit
_func()
return self.get(request, *args, **kwargs) return self.get(request, *args, **kwargs)