|
7 | 7 |
|
8 | 8 | import asyncio
|
9 | 9 | import concurrent.futures
|
| 10 | +import json |
10 | 11 | import logging
|
11 | 12 | import os
|
12 | 13 | import platform
|
|
62 | 63 | from .utils.app_setting_manager import get_python_appsetting_state
|
63 | 64 | from .utils.common import get_app_setting, is_envvar_true, validate_script_file_name
|
64 | 65 | from .utils.dependency import DependencyManager
|
| 66 | +from .utils.kernel_manager import KernelHandler |
65 | 67 | from .utils.tracing import marshall_exception_trace
|
66 | 68 | from .utils.wrappers import disable_feature_by
|
67 | 69 | from .version import VERSION
|
@@ -601,9 +603,14 @@ async def _handle__invocation_request(self, request):
|
601 | 603 | current_task.set_azure_invocation_id(invocation_id)
|
602 | 604 |
|
603 | 605 | try:
|
| 606 | + # Execute things here |
| 607 | + |
604 | 608 | fi: functions.FunctionInfo = self._functions.get_function(
|
605 | 609 | function_id)
|
606 | 610 | assert fi is not None
|
| 611 | + logger.info("Starting kernel handler...") |
| 612 | + kernel_handler = KernelHandler() |
| 613 | + logger.info("Kernel handler successfully started!") |
607 | 614 |
|
608 | 615 | function_invocation_logs: List[str] = [
|
609 | 616 | 'Received FunctionInvocationRequest',
|
@@ -655,36 +662,44 @@ async def _handle__invocation_request(self, request):
|
655 | 662 |
|
656 | 663 | fi_context = self._get_context(invoc_request, fi.name,
|
657 | 664 | fi.directory)
|
| 665 | + |
| 666 | + logger.info("Starting execution using kernel...") |
| 667 | + code_json = invoc_request.trigger_metadata.get('mcptoolargs').json |
| 668 | + logger.info("Full request: %s, Received code from request: %s, Type of object: %s", invoc_request, code_json, type(code_json)) |
| 669 | + code = json.dumps(code_json) |
| 670 | + logger.info("Parsed code from request: %s", code) |
| 671 | + call_result = kernel_handler.run_code(code) |
| 672 | + logger.info("Execution completed successfully! Result: %s", call_result) |
658 | 673 |
|
659 | 674 | # Use local thread storage to store the invocation ID
|
660 | 675 | # for a customer's threads
|
661 |
| - fi_context.thread_local_storage.invocation_id = invocation_id |
662 |
| - if fi.requires_context: |
663 |
| - args['context'] = fi_context |
664 |
| - |
665 |
| - if fi.output_types: |
666 |
| - for name in fi.output_types: |
667 |
| - args[name] = bindings.Out() |
668 |
| - |
669 |
| - if fi.is_async: |
670 |
| - if self._azure_monitor_available or self._otel_libs_available: |
671 |
| - self.configure_opentelemetry(fi_context) |
672 |
| - |
673 |
| - call_result = \ |
674 |
| - await self._run_async_func(fi_context, fi.func, args) |
675 |
| - else: |
676 |
| - call_result = await self._loop.run_in_executor( |
677 |
| - self._sync_call_tp, |
678 |
| - self._run_sync_func, |
679 |
| - invocation_id, fi_context, fi.func, args) |
680 |
| - |
681 |
| - if call_result is not None and not fi.has_return: |
682 |
| - raise RuntimeError( |
683 |
| - f'function {fi.name!r} without a $return binding' |
684 |
| - 'returned a non-None value') |
685 |
| - |
686 |
| - if http_v2_enabled: |
687 |
| - http_coordinator.set_http_response(invocation_id, call_result) |
| 676 | + # fi_context.thread_local_storage.invocation_id = invocation_id |
| 677 | + # if fi.requires_context: |
| 678 | + # args['context'] = fi_context |
| 679 | + |
| 680 | + # if fi.output_types: |
| 681 | + # for name in fi.output_types: |
| 682 | + # args[name] = bindings.Out() |
| 683 | + |
| 684 | + # if fi.is_async: |
| 685 | + # if self._azure_monitor_available or self._otel_libs_available: |
| 686 | + # self.configure_opentelemetry(fi_context) |
| 687 | + |
| 688 | + # call_result = \ |
| 689 | + # await self._run_async_func(fi_context, fi.func, args) |
| 690 | + # else: |
| 691 | + # call_result = await self._loop.run_in_executor( |
| 692 | + # self._sync_call_tp, |
| 693 | + # self._run_sync_func, |
| 694 | + # invocation_id, fi_context, fi.func, args) |
| 695 | + |
| 696 | + # if call_result is not None and not fi.has_return: |
| 697 | + # raise RuntimeError( |
| 698 | + # f'function {fi.name!r} without a $return binding' |
| 699 | + # 'returned a non-None value') |
| 700 | + |
| 701 | + # if http_v2_enabled: |
| 702 | + # http_coordinator.set_http_response(invocation_id, call_result) |
688 | 703 |
|
689 | 704 | output_data = []
|
690 | 705 | cache_enabled = self._function_data_cache_enabled
|
|
0 commit comments