pixelarraythirdparty 1.0.3__tar.gz → 1.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/PKG-INFO +1 -1
  2. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty/__init__.py +1 -1
  3. pixelarraythirdparty-1.0.5/pixelarraythirdparty/celery/celery.py +156 -0
  4. pixelarraythirdparty-1.0.5/pixelarraythirdparty/client.py +47 -0
  5. pixelarraythirdparty-1.0.5/pixelarraythirdparty/order/order.py +661 -0
  6. pixelarraythirdparty-1.0.5/pixelarraythirdparty/product/product.py +287 -0
  7. pixelarraythirdparty-1.0.5/pixelarraythirdparty/user/user.py +227 -0
  8. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty.egg-info/PKG-INFO +1 -1
  9. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pyproject.toml +1 -1
  10. pixelarraythirdparty-1.0.3/pixelarraythirdparty/celery/celery.py +0 -37
  11. pixelarraythirdparty-1.0.3/pixelarraythirdparty/client.py +0 -22
  12. pixelarraythirdparty-1.0.3/pixelarraythirdparty/order/order.py +0 -110
  13. pixelarraythirdparty-1.0.3/pixelarraythirdparty/product/product.py +0 -104
  14. pixelarraythirdparty-1.0.3/pixelarraythirdparty/user/user.py +0 -69
  15. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/LICENSE +0 -0
  16. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/MANIFEST.in +0 -0
  17. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty/celery/__init__.py +0 -0
  18. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty/order/__init__.py +0 -0
  19. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty/product/__init__.py +0 -0
  20. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty/user/__init__.py +0 -0
  21. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty.egg-info/SOURCES.txt +0 -0
  22. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty.egg-info/dependency_links.txt +0 -0
  23. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty.egg-info/requires.txt +0 -0
  24. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/pixelarraythirdparty.egg-info/top_level.txt +0 -0
  25. {pixelarraythirdparty-1.0.3 → pixelarraythirdparty-1.0.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraythirdparty
3
- Version: 1.0.3
3
+ Version: 1.0.5
4
4
  Summary: PixelArray 第三方微服务客户端
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -10,7 +10,7 @@ PixelArray 第三方微服务客户端
10
10
  - user: 用户管理模块
11
11
  """
12
12
 
13
- __version__ = "1.0.3"
13
+ __version__ = "1.0.5"
14
14
  __author__ = "Lu qi"
15
15
  __email__ = "qi.lu@pixelarrayai.com"
16
16
 
@@ -0,0 +1,156 @@
1
+ from pixelarraythirdparty.client import Client
2
+
3
+
4
+ class CeleryManager(Client):
5
+ def get_celery_status(self):
6
+ """
7
+ 获取Celery服务状态
8
+
9
+ 功能说明:
10
+ 获取Celery服务的运行状态,包括已注册的任务、工作节点状态等。
11
+
12
+ 输入参数:
13
+
14
+
15
+ 返回字段:
16
+ data (dict): Celery服务状态信息
17
+ - registered_tasks (dict): 已注册的任务列表,按工作节点分组
18
+ - worker_stats (dict): 工作节点统计信息
19
+ - scheduled_task_count (int): 定时任务数量
20
+ - timestamp (str): 状态获取时间
21
+ success (bool): 操作是否成功
22
+
23
+ 异常情况:
24
+ - 获取Celery状态失败:返回错误信息"获取Celery状态失败"
25
+ """
26
+ data, success = self._request("GET", "/api/celery/status")
27
+ if not success:
28
+ return {}, False
29
+ return data, True
30
+
31
+ def get_celery_tasks(self):
32
+ """
33
+ 获取已注册任务列表
34
+
35
+ 功能说明:
36
+ 获取所有已注册的Celery任务列表。
37
+
38
+ 输入参数:
39
+
40
+
41
+ 返回字段:
42
+ data (dict): 任务列表信息
43
+ - tasks (list): 已注册的任务名称列表
44
+ - count (int): 任务数量
45
+ - timestamp (str): 获取时间
46
+ success (bool): 操作是否成功
47
+
48
+ 异常情况:
49
+ - 获取任务列表失败:返回错误信息"获取任务列表失败"
50
+ """
51
+ data, success = self._request("GET", "/api/celery/tasks")
52
+ if not success:
53
+ return {}, False
54
+ return data, True
55
+
56
+ def get_celery_tasks_scheduled(self):
57
+ """
58
+ 获取定时任务列表
59
+
60
+ 功能说明:
61
+ 获取所有配置的定时任务列表,包括任务详情、执行时间、状态等。
62
+
63
+ 输入参数:
64
+
65
+
66
+ 返回字段:
67
+ data (dict): 定时任务列表信息
68
+ - tasks (list): 定时任务列表
69
+ - id (str): 任务ID
70
+ - name (str): 任务名称
71
+ - description (str): 任务描述
72
+ - schedule (str): 执行时间
73
+ - enabled (bool): 是否启用
74
+ - task_name (str): 任务函数名
75
+ - module_name (str): 模块名
76
+ - function_name (str): 函数名
77
+ - file_path (str): 文件路径
78
+ - parameters (list): 参数列表
79
+ - task_config (dict): 任务配置
80
+ - registration_info (dict): 注册信息
81
+ - count (int): 任务数量
82
+ - timestamp (str): 获取时间
83
+ success (bool): 操作是否成功
84
+
85
+ 异常情况:
86
+ - 获取定时任务列表失败:返回错误信息"获取定时任务列表失败"
87
+ """
88
+ data, success = self._request("GET", "/api/celery/tasks/scheduled")
89
+ if not success:
90
+ return {}, False
91
+ return data, True
92
+
93
+ def get_celery_tasks_detail(self, task_name: str):
94
+ """
95
+ 获取任务详情
96
+
97
+ 功能说明:
98
+ 根据任务名称获取指定任务的详细信息。
99
+
100
+ 输入参数:
101
+ task_name (str): 任务名称,必填,需要URL编码
102
+
103
+ 返回字段:
104
+ data (dict): 任务详细信息
105
+ - task_name (str): 任务名称
106
+ - module_name (str): 模块名
107
+ - function_name (str): 函数名
108
+ - file_path (str): 文件路径
109
+ - description (str): 任务描述
110
+ - parameters (list): 参数列表
111
+ - task_config (dict): 任务配置
112
+ - registration_info (dict): 注册信息
113
+ - timestamp (str): 获取时间
114
+ success (bool): 操作是否成功
115
+
116
+ 异常情况:
117
+ - 任务不存在:返回错误信息"任务不存在"
118
+ - 获取任务详情失败:返回错误信息"获取任务详情失败"
119
+ """
120
+ data, success = self._request("GET", f"/api/celery/tasks/{task_name}")
121
+ if not success:
122
+ return {}, False
123
+ return data, True
124
+
125
+ def trigger_celery_task(self, task_name: str, args: list, kwargs: dict):
126
+ """
127
+ 触发任务执行
128
+
129
+ 功能说明:
130
+ 手动触发指定任务的执行,支持传递参数。
131
+
132
+ 输入参数:
133
+ task_name (str): 任务名称,必填,需要URL编码
134
+ args (list): 任务参数列表,可选
135
+ kwargs (dict): 任务关键字参数,可选
136
+
137
+ 返回字段:
138
+ data (dict): 任务触发信息
139
+ - task_id (str): 任务ID
140
+ - task_name (str): 任务名称
141
+ - status (str): 任务状态,初始为"PENDING"
142
+ - message (str): 触发消息
143
+ success (bool): 操作是否成功
144
+
145
+ 异常情况:
146
+ - 任务不存在:返回错误信息"任务不存在"
147
+ - 任务触发失败:返回错误信息"任务触发失败"
148
+ """
149
+ data, success = self._request(
150
+ "POST",
151
+ f"/api/celery/tasks/{task_name}/trigger",
152
+ json={"args": args, "kwargs": kwargs},
153
+ )
154
+ if not success:
155
+ return {}, False
156
+ return data, True
@@ -0,0 +1,47 @@
1
+ import requests
2
+ import aiohttp
3
+ from typing import Dict, Any, Optional, Tuple
4
+ import asyncio
5
+
6
+
7
+ class Client:
8
+ """基础认证类,提供公共的 API key 认证和请求方法"""
9
+
10
+ def __init__(self, api_key: str):
11
+ self.base_url = "https://thirdparty.pixelarrayai.com"
12
+ self.api_key = api_key
13
+ self.headers = {
14
+ "Content-Type": "application/json",
15
+ "X-API-Key": self.api_key,
16
+ }
17
+
18
+ def _request(self, method: str, url: str, **kwargs) -> Tuple[Dict[str, Any], bool]:
19
+ """统一的请求方法"""
20
+ resp = requests.request(
21
+ method, f"{self.base_url}{url}", headers=self.headers, **kwargs
22
+ )
23
+ if resp.status_code == 200 and resp.json().get("success") is True:
24
+ return resp.json().get("data", {}), True
25
+ return {}, False
26
+
27
+
28
+ class AsyncClient:
29
+ def __init__(self, api_key: str):
30
+ self.base_url = "https://thirdparty.pixelarrayai.com"
31
+ self.api_key = api_key
32
+ self.headers = {
33
+ "Content-Type": "application/json",
34
+ "X-API-Key": self.api_key,
35
+ }
36
+
37
+ async def _request(self, method: str, url: str, **kwargs) -> Tuple[Dict[str, Any], bool]:
38
+ async with aiohttp.ClientSession() as session:
39
+ req_method = getattr(session, method.lower())
40
+ async with req_method(
41
+ f"{self.base_url}{url}", headers=self.headers, **kwargs
42
+ ) as resp:
43
+ if resp.status == 200:
44
+ result = await resp.json()
45
+ if result.get("success") is True:
46
+ return result.get("data", {}), True
47
+ return {}, False