Skip to content

Commit 3f685dc

Browse files
committed
Adding ServicesGrouping.pyproj
1 parent e7c6892 commit 3f685dc

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
lines changed

PyWebApi.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdomdClient_From_NuGet", "S
2020
EndProject
2121
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Utilities.PyPI", "Utilities.PyPI\Utilities.PyPI.pyproj", "{DA5BA1E0-95BC-48CD-B94F-EB972F0A602E}"
2222
EndProject
23+
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "ServicesGrouping", "Sample\UserApps\ServicesGrouping\ServicesGrouping.pyproj", "{3531393B-7964-486F-B517-BDDF01EB96DA}"
24+
EndProject
2325
Global
2426
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2527
Debug|Any CPU = Debug|Any CPU
@@ -42,6 +44,8 @@ Global
4244
{92BA630D-18B4-448C-B9D6-10698C74EEEE}.Release|Any CPU.Build.0 = Release|Any CPU
4345
{DA5BA1E0-95BC-48CD-B94F-EB972F0A602E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4446
{DA5BA1E0-95BC-48CD-B94F-EB972F0A602E}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{3531393B-7964-486F-B517-BDDF01EB96DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48+
{3531393B-7964-486F-B517-BDDF01EB96DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
4549
EndGlobalSection
4650
GlobalSection(SolutionProperties) = preSolution
4751
HideSolutionNode = FALSE
@@ -51,6 +55,7 @@ Global
5155
{1A1E573F-1382-4AB0-9FE6-5331B5F95D66} = {F7AC17AC-4CBD-4DD8-94E5-21DC54244474}
5256
{ADC55014-753C-41C9-AA62-32D29CEB7248} = {1A1E573F-1382-4AB0-9FE6-5331B5F95D66}
5357
{92BA630D-18B4-448C-B9D6-10698C74EEEE} = {1A1E573F-1382-4AB0-9FE6-5331B5F95D66}
58+
{3531393B-7964-486F-B517-BDDF01EB96DA} = {1A1E573F-1382-4AB0-9FE6-5331B5F95D66}
5459
EndGlobalSection
5560
GlobalSection(ExtensibilityGlobals) = postSolution
5661
SolutionGuid = {C2FBDAEC-0FDE-4D17-B908-AA8C1DB16A5B}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
2+
<PropertyGroup>
3+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4+
<SchemaVersion>2.0</SchemaVersion>
5+
<ProjectGuid>3531393b-7964-486f-b517-bddf01eb96da</ProjectGuid>
6+
<ProjectHome>.</ProjectHome>
7+
<StartupFile>rest_grouping.py</StartupFile>
8+
<SearchPath>
9+
</SearchPath>
10+
<WorkingDirectory>.</WorkingDirectory>
11+
<OutputPath>.</OutputPath>
12+
<Name>ServicesGrouping</Name>
13+
<RootNamespace>ServicesGrouping</RootNamespace>
14+
<InterpreterId>MSBuild|env|$(MSBuildProjectFullPath)</InterpreterId>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
23+
</PropertyGroup>
24+
<ItemGroup>
25+
<Compile Include="rest_grouping.py" />
26+
</ItemGroup>
27+
<ItemGroup>
28+
<Content Include="deploy.bat" />
29+
<Content Include="pywebapi.pth" />
30+
<Content Include="requirements.txt" />
31+
</ItemGroup>
32+
<ItemGroup>
33+
<Interpreter Include="env\">
34+
<Id>env</Id>
35+
<Version>3.6</Version>
36+
<Description>env (Python 3.6 (64-bit))</Description>
37+
<InterpreterPath>Scripts\python.exe</InterpreterPath>
38+
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
39+
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
40+
<Architecture>X64</Architecture>
41+
</Interpreter>
42+
</ItemGroup>
43+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
44+
<!-- Uncomment the CoreCompile target to enable the Build command in
45+
Visual Studio and specify your pre- and post-build commands in
46+
the BeforeBuild and AfterBuild targets below. -->
47+
<!--<Target Name="CoreCompile" />-->
48+
<Target Name="BeforeBuild">
49+
</Target>
50+
<Target Name="AfterBuild">
51+
</Target>
52+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@Echo off
2+
CD /d "%~dp0"
3+
IF "%~1"=="" (
4+
SET "DESTINATION=..\..\PyWebApi.IIS\user-script-root\utilities\services_grouping"
5+
) ELSE (
6+
SET "DESTINATION=%~1"
7+
)
8+
9+
RoboCopy . "%DESTINATION%" /s /purge /xf *.pyproj deploy.bat /xd __pycache__
10+
11+
SETLOCAL EnableDelayedExpansion EnableExtensions
12+
FOR /f "delims=" %%i in ('dir pywintypes??.dll /s /b') DO (
13+
SET SOURCE=%%i
14+
IF "!SOURCE:~-4!"==".dll" (
15+
Copy "!SOURCE!" "!DESTINATION!" /y
16+
)
17+
)
18+
ENDLOCAL
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
env\Lib\site-packages
2+
env\Lib\site-packages\win32
3+
env\Lib\site-packages\win32\lib
4+
5+
#copy pywintypes??.dll from env\Lib\site-packages\pywin32_system32 to env\Lib\site-packages\win32\lib
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
task-grouping
2+
simple-rest-call
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# -*- coding: utf-8 -*-
2+
"""rest_grouping.py
3+
4+
This module implements ``RestTaskLoader`` class, which is used to load a group of RESTful services (call tasks) from a JSON payload into ``TaskContainer``.
5+
6+
This module was originally shipped as an example code from https://github.com/DataBooster/PyWebApi, licensed under the MIT license.
7+
Anyone who obtains a copy of this code is welcome to modify it for any purpose, and holds all rights to the modified part only.
8+
The above license notice and permission notice shall be included in all copies or substantial portions of the Software.
9+
"""
10+
from typing import List, Tuple, Dict, Any
11+
from concurrent.futures import ThreadPoolExecutor
12+
from task_grouping import TaskContainer, ITaskLoader
13+
from simple_rest_call import request_json
14+
15+
16+
_reserved_key_parallel_group : str = '[###]'
17+
_reserved_key_serial_group : str = '[+++]'
18+
_reserved_key_rest_url : str = '(://)'
19+
_reserved_key_payload : str = '(...)'
20+
_reserved_key_payload_with_pipe : str = '(.|.)'
21+
22+
23+
def _pipeargs_merge_fn(kw_args:Dict[str, Any], pipe_args:Dict[str, Any]) -> Dict[str, Any]:
24+
if pipe_args and isinstance(pipe_args, dict):
25+
merged_args = kw_args.copy() if kw_args else {}
26+
payload = kw_args.get('data', {})
27+
if payload is None:
28+
payload = {}
29+
30+
if isinstance(payload, dict):
31+
merged_args['data'] = payload.copy().update(pipe_args)
32+
33+
return merged_args
34+
else:
35+
return kw_args
36+
37+
38+
class RestTaskLoader(ITaskLoader):
39+
"""This class is used to load a group of RESTful services (call tasks) from a JSON payload into ``TaskContainer``"""
40+
def __init__(self, thread_pool:ThreadPoolExecutor):
41+
self.thread_pool = thread_pool
42+
self.func = request_json
43+
self.merge_fn = _pipeargs_merge_fn
44+
self.timeout = None
45+
46+
47+
def create_base_container(self) -> TaskContainer:
48+
return TaskContainer(self.func, self.merge_fn, self.thread_pool, **{'timeout':self.timeout})
49+
50+
51+
def extract_single_task(self, task_node:Dict[str, Any]) -> Tuple[tuple, Dict[str, Any], bool]:
52+
url = task_node.get(_reserved_key_rest_url)
53+
if url:
54+
data = task_node.get(_reserved_key_payload)
55+
if data is None:
56+
data = {}
57+
58+
data_ = task_node.get(_reserved_key_payload_with_pipe)
59+
if data_ is not None or _reserved_key_payload_with_pipe in task_node:
60+
if data_:
61+
data.update(data_)
62+
with_pipe = True
63+
else:
64+
with_pipe = False
65+
66+
return ((), {'url': url, 'data': data}, with_pipe)
67+
else:
68+
return None
69+
70+
71+
def extract_serial_group(self, task_node:Dict[str, Any]) -> List[Dict[str, Any]]:
72+
return task_node.get(_reserved_key_serial_group)
73+
74+
75+
def extract_parallel_group(self, task_node:Dict[str, Any]) -> List[Dict[str, Any]]:
76+
return task_node.get(_reserved_key_parallel_group)

0 commit comments

Comments
 (0)