mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 21:25:42 +00:00 
			
		
		
		
	use direct import instead of text for offload
This commit is contained in:
		| @@ -11,6 +11,7 @@ from django.utils import timezone | ||||
|  | ||||
| from django.core.exceptions import AppRegistryNotReady | ||||
| from django.db.utils import OperationalError, ProgrammingError | ||||
| from django.core import mail as django_mail | ||||
|  | ||||
|  | ||||
| logger = logging.getLogger("inventree") | ||||
| @@ -292,7 +293,7 @@ def send_email(subject, body, recipients, from_email=None, html_message=None): | ||||
|         recipients = [recipients] | ||||
|  | ||||
|     offload_task( | ||||
|         'django.core.mail.send_mail', | ||||
|         django_mail.send_mail, | ||||
|         subject, | ||||
|         body, | ||||
|         from_email, | ||||
|   | ||||
| @@ -797,13 +797,9 @@ class CurrencyRefreshView(RedirectView): | ||||
|         On a POST request we will attempt to refresh the exchange rates | ||||
|         """ | ||||
|  | ||||
|         from InvenTree.tasks import offload_task | ||||
|         from InvenTree.tasks import offload_task, update_exchange_rates | ||||
|  | ||||
|         # Define associated task from InvenTree.tasks list of methods | ||||
|         taskname = 'InvenTree.tasks.update_exchange_rates' | ||||
|  | ||||
|         # Run it | ||||
|         offload_task(taskname, force_sync=True) | ||||
|         offload_task(update_exchange_rates, force_sync=True) | ||||
|  | ||||
|         return redirect(reverse_lazy('settings')) | ||||
|  | ||||
|   | ||||
| @@ -41,6 +41,7 @@ from plugin.events import trigger_event | ||||
| from part import models as PartModels | ||||
| from stock import models as StockModels | ||||
| from users import models as UserModels | ||||
| from . import tasks as build_tasks | ||||
|  | ||||
|  | ||||
| def get_next_build_number(): | ||||
| @@ -1146,7 +1147,7 @@ def after_save_build(sender, instance: Build, created: bool, **kwargs): | ||||
|         # A new Build has just been created | ||||
|  | ||||
|         # Run checks on required parts | ||||
|         InvenTree.tasks.offload_task('build.tasks.check_build_stock', instance) | ||||
|         InvenTree.tasks.offload_task(build_tasks.check_build_stock, instance) | ||||
|  | ||||
|  | ||||
| class BuildOrderAttachment(InvenTreeAttachment): | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
| from django.test import TestCase | ||||
|  | ||||
| from common.models import NotificationEntry | ||||
| from . import tasks as common_tasks | ||||
| from InvenTree.tasks import offload_task | ||||
|  | ||||
|  | ||||
| @@ -14,4 +15,4 @@ class TaskTest(TestCase): | ||||
|  | ||||
|         # check empty run | ||||
|         self.assertEqual(NotificationEntry.objects.all().count(), 0) | ||||
|         offload_task('common.tasks.delete_old_notifications',) | ||||
|         offload_task(common_tasks.delete_old_notifications,) | ||||
|   | ||||
| @@ -24,6 +24,7 @@ from plugin.registry import registry | ||||
|  | ||||
| from stock.models import StockItem, StockLocation | ||||
| from part.models import Part | ||||
| from plugin.base.label import label as plugin_label | ||||
|  | ||||
| from .models import StockItemLabel, StockLocationLabel, PartLabel | ||||
| from .serializers import StockItemLabelSerializer, StockLocationLabelSerializer, PartLabelSerializer | ||||
| @@ -156,7 +157,7 @@ class LabelPrintMixin: | ||||
|  | ||||
|                 # Offload a background task to print the provided label | ||||
|                 offload_task( | ||||
|                     'plugin.base.label.label.print_label', | ||||
|                     plugin_label.print_label, | ||||
|                     plugin.plugin_slug(), | ||||
|                     image, | ||||
|                     label_instance=label_instance, | ||||
|   | ||||
| @@ -63,6 +63,7 @@ from stock import models as StockModels | ||||
| import common.models | ||||
|  | ||||
| import part.settings as part_settings | ||||
| from part import tasks as part_tasks | ||||
|  | ||||
|  | ||||
| logger = logging.getLogger("inventree") | ||||
| @@ -2298,7 +2299,7 @@ def after_save_part(sender, instance: Part, created, **kwargs): | ||||
|         # Check part stock only if we are *updating* the part (not creating it) | ||||
|  | ||||
|         # Run this check in the background | ||||
|         InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance) | ||||
|         InvenTree.tasks.offload_task(part_tasks.notify_low_stock_if_required, instance) | ||||
|  | ||||
|  | ||||
| class PartAttachment(InvenTreeAttachment): | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import InvenTree.tasks | ||||
| import common.notifications | ||||
|  | ||||
| import part.models | ||||
| from part import tasks as part_tasks | ||||
|  | ||||
| logger = logging.getLogger("inventree") | ||||
|  | ||||
| @@ -49,6 +50,6 @@ def notify_low_stock_if_required(part: part.models.Part): | ||||
|     for p in parts: | ||||
|         if p.is_part_low_on_stock(): | ||||
|             InvenTree.tasks.offload_task( | ||||
|                 'part.tasks.notify_low_stock', | ||||
|                 part_tasks.notify_low_stock, | ||||
|                 p | ||||
|             ) | ||||
|   | ||||
| @@ -49,6 +49,7 @@ from users.models import Owner | ||||
|  | ||||
| from company import models as CompanyModels | ||||
| from part import models as PartModels | ||||
| from part import tasks as part_tasks | ||||
|  | ||||
|  | ||||
| class StockLocation(InvenTreeTree): | ||||
| @@ -2026,7 +2027,7 @@ def after_delete_stock_item(sender, instance: StockItem, **kwargs): | ||||
|  | ||||
|     if not InvenTree.ready.isImportingData(): | ||||
|         # Run this check in the background | ||||
|         InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance.part) | ||||
|         InvenTree.tasks.offload_task(part_tasks.notify_low_stock_if_required, instance.part) | ||||
|  | ||||
|  | ||||
| @receiver(post_save, sender=StockItem, dispatch_uid='stock_item_post_save_log') | ||||
| @@ -2037,7 +2038,7 @@ def after_save_stock_item(sender, instance: StockItem, created, **kwargs): | ||||
|  | ||||
|     if not InvenTree.ready.isImportingData(): | ||||
|         # Run this check in the background | ||||
|         InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance.part) | ||||
|         InvenTree.tasks.offload_task(part_tasks.notify_low_stock_if_required, instance.part) | ||||
|  | ||||
|  | ||||
| class StockItemAttachment(InvenTreeAttachment): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user