CheeseAPI 2.0.5b4__tar.gz → 2.0.6b1__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.
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/app.py +36 -97
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/file.py +1 -3
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/request.py +1 -3
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/route.py +3 -9
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/scheduler.py +33 -57
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/signal.py +14 -42
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/websocket.py +1 -1
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/PKG-INFO +1 -1
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/pyproject.toml +1 -1
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/.gitignore +0 -0
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/__init__.py +0 -0
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/cors.py +0 -0
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/printer.py +0 -0
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/response.py +0 -0
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/static.py +0 -0
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/CheeseAPI/validator.py +0 -0
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/LICENSE +0 -0
- {cheeseapi-2.0.5b4 → cheeseapi-2.0.6b1}/README.md +0 -0
|
@@ -334,7 +334,10 @@ class AppProxy:
|
|
|
334
334
|
async def get_response(self, request: Request) -> Response:
|
|
335
335
|
if inspect.isfunction(request.fn):
|
|
336
336
|
try:
|
|
337
|
-
|
|
337
|
+
if 'request' in inspect.signature(request.fn).parameters:
|
|
338
|
+
return await request.fn(request = request)
|
|
339
|
+
else:
|
|
340
|
+
return await request.fn()
|
|
338
341
|
except Exception as e:
|
|
339
342
|
self.app.printer.fn_error(e, request)
|
|
340
343
|
return Response(status = 500)
|
|
@@ -590,169 +593,127 @@ class CheeseAPI:
|
|
|
590
593
|
|
|
591
594
|
@property
|
|
592
595
|
def logger_path(self) -> str | None:
|
|
593
|
-
'''
|
|
594
|
-
日志文件路径,支持日期格式化
|
|
595
|
-
'''
|
|
596
|
+
''' 日志文件路径,支持日期格式化 '''
|
|
596
597
|
|
|
597
598
|
return self._logger_path
|
|
598
599
|
|
|
599
600
|
@property
|
|
600
601
|
def dual_stack(self) -> bool:
|
|
601
|
-
'''
|
|
602
|
-
是否启用双栈支持;若系统不支持,则自动回退
|
|
603
|
-
'''
|
|
602
|
+
''' 是否启用双栈支持;若系统不支持,则自动回退 '''
|
|
604
603
|
|
|
605
604
|
return self._dual_stack
|
|
606
605
|
|
|
607
606
|
@property
|
|
608
607
|
def socket_backlog(self) -> int | None:
|
|
609
|
-
'''
|
|
610
|
-
最大连接数
|
|
611
|
-
'''
|
|
608
|
+
''' 最大连接数 '''
|
|
612
609
|
|
|
613
610
|
return self._socket_backlog
|
|
614
611
|
|
|
615
612
|
@property
|
|
616
613
|
def socket_send_buffer_size(self) -> int | None:
|
|
617
|
-
'''
|
|
618
|
-
发送缓冲区大小
|
|
619
|
-
'''
|
|
614
|
+
''' 发送缓冲区大小 '''
|
|
620
615
|
|
|
621
616
|
return self._socket_send_buffer_size
|
|
622
617
|
|
|
623
618
|
@property
|
|
624
619
|
def socket_receive_buffer_size(self) -> int | None:
|
|
625
|
-
'''
|
|
626
|
-
接收缓冲区大小
|
|
627
|
-
'''
|
|
620
|
+
''' 接收缓冲区大小 '''
|
|
628
621
|
|
|
629
622
|
return self._socket_receive_buffer_size
|
|
630
623
|
|
|
631
624
|
@property
|
|
632
625
|
def workers(self) -> int:
|
|
633
|
-
'''
|
|
634
|
-
工作进程数
|
|
635
|
-
'''
|
|
626
|
+
''' 工作进程数 '''
|
|
636
627
|
|
|
637
628
|
return self._workers
|
|
638
629
|
|
|
639
630
|
@property
|
|
640
631
|
def ssl_cert(self) -> str | None:
|
|
641
|
-
'''
|
|
642
|
-
SSL 证书路径
|
|
643
|
-
'''
|
|
632
|
+
''' SSL 证书路径 '''
|
|
644
633
|
|
|
645
634
|
return self._ssl_cert
|
|
646
635
|
|
|
647
636
|
@property
|
|
648
637
|
def ssl_key(self) -> str | None:
|
|
649
|
-
'''
|
|
650
|
-
SSL 密钥路径
|
|
651
|
-
'''
|
|
638
|
+
''' SSL 密钥路径 '''
|
|
652
639
|
|
|
653
640
|
return self._ssl_key
|
|
654
641
|
|
|
655
642
|
@property
|
|
656
643
|
def sync_server_url(self) -> str | None:
|
|
657
|
-
'''
|
|
658
|
-
同步服务器地址,用于多进程间同步数据;支持redis
|
|
659
|
-
'''
|
|
644
|
+
''' 同步服务器地址,用于多进程间同步数据;支持redis '''
|
|
660
645
|
|
|
661
646
|
return self._sync_server_url
|
|
662
647
|
|
|
663
648
|
@property
|
|
664
649
|
def static_path(self) -> dict[str, str]:
|
|
665
|
-
'''
|
|
666
|
-
静态文件路径映射,格式为`{url_path: file_system_path}`
|
|
667
|
-
'''
|
|
650
|
+
''' 静态文件路径映射,格式为`{url_path: file_system_path}` '''
|
|
668
651
|
|
|
669
652
|
return self._static_path
|
|
670
653
|
|
|
671
654
|
@property
|
|
672
655
|
def printer(self) -> Type[Printer]:
|
|
673
|
-
'''
|
|
674
|
-
自定义消息输出
|
|
675
|
-
'''
|
|
656
|
+
''' 自定义消息输出 '''
|
|
676
657
|
|
|
677
658
|
return self._printer
|
|
678
659
|
|
|
679
660
|
@property
|
|
680
661
|
def compress(self) -> list[Literal['gzip', 'br', 'zstd', 'deflate']]:
|
|
681
|
-
'''
|
|
682
|
-
支持的压缩算法,按照顺序尝试压缩
|
|
683
|
-
'''
|
|
662
|
+
''' 支持的压缩算法,按照顺序尝试压缩 '''
|
|
684
663
|
|
|
685
664
|
return self._compress
|
|
686
665
|
|
|
687
666
|
@property
|
|
688
667
|
def compress_min_length(self) -> int:
|
|
689
|
-
'''
|
|
690
|
-
启用压缩的最小响应体长度
|
|
691
|
-
'''
|
|
668
|
+
''' 启用压缩的最小响应体长度 '''
|
|
692
669
|
|
|
693
670
|
return self._compress_min_length
|
|
694
671
|
|
|
695
672
|
@property
|
|
696
673
|
def compress_level(self) -> int:
|
|
697
|
-
'''
|
|
698
|
-
压缩等级,每个算法的压缩级别可能不同,详见各算法文档
|
|
699
|
-
'''
|
|
674
|
+
''' 压缩等级,每个算法的压缩级别可能不同,详见各算法文档 '''
|
|
700
675
|
|
|
701
676
|
return self._compress_level
|
|
702
677
|
|
|
703
678
|
@property
|
|
704
679
|
def manual_modules(self) -> list[str]:
|
|
705
|
-
'''
|
|
706
|
-
手动加载的模块列表
|
|
707
|
-
'''
|
|
680
|
+
''' 手动加载的模块列表 '''
|
|
708
681
|
|
|
709
682
|
return self._manual_modules
|
|
710
683
|
|
|
711
684
|
@property
|
|
712
685
|
def exclude_modules(self) -> list[str]:
|
|
713
|
-
'''
|
|
714
|
-
排除加载的模块列表
|
|
715
|
-
'''
|
|
686
|
+
''' 排除加载的模块列表 '''
|
|
716
687
|
|
|
717
688
|
return self._exclude_modules
|
|
718
689
|
|
|
719
690
|
@property
|
|
720
691
|
def priority_modules(self) -> list[str]:
|
|
721
|
-
'''
|
|
722
|
-
优先加载的模块列表
|
|
723
|
-
'''
|
|
692
|
+
''' 优先加载的模块列表 '''
|
|
724
693
|
|
|
725
694
|
return self._priority_modules
|
|
726
695
|
|
|
727
696
|
@property
|
|
728
697
|
def sync_server_data_encode(self) -> Callable[[bytes], bytes] | None:
|
|
729
|
-
'''
|
|
730
|
-
同步服务器数据编码处理函数
|
|
731
|
-
'''
|
|
698
|
+
''' 同步服务器数据编码处理函数 '''
|
|
732
699
|
|
|
733
700
|
return self._sync_server_data_encode
|
|
734
701
|
|
|
735
702
|
@property
|
|
736
703
|
def sync_server_data_decode(self) -> Callable[[bytes], bytes] | None:
|
|
737
|
-
'''
|
|
738
|
-
同步服务器数据解码处理函数
|
|
739
|
-
'''
|
|
704
|
+
''' 同步服务器数据解码处理函数 '''
|
|
740
705
|
|
|
741
706
|
return self._sync_server_data_decode
|
|
742
707
|
|
|
743
708
|
@property
|
|
744
709
|
def logger_messages(self) -> dict[str, 'Message']:
|
|
745
|
-
'''
|
|
746
|
-
归属于 CheeseAPI 日志的消息列表
|
|
747
|
-
'''
|
|
710
|
+
''' 归属于 CheeseAPI 日志的消息列表 '''
|
|
748
711
|
|
|
749
712
|
return self._logger_messages
|
|
750
713
|
|
|
751
714
|
@property
|
|
752
715
|
def logger(self) -> CheeseLogger:
|
|
753
|
-
'''
|
|
754
|
-
归属于 CheeseAPI 日志实例
|
|
755
|
-
'''
|
|
716
|
+
''' 归属于 CheeseAPI 日志实例 '''
|
|
756
717
|
|
|
757
718
|
return self._logger
|
|
758
719
|
|
|
@@ -770,9 +731,7 @@ class CheeseAPI:
|
|
|
770
731
|
|
|
771
732
|
@property
|
|
772
733
|
def keep_alive(self) -> bool:
|
|
773
|
-
'''
|
|
774
|
-
是否启用长连接
|
|
775
|
-
'''
|
|
734
|
+
''' 是否启用长连接 '''
|
|
776
735
|
|
|
777
736
|
return self._keep_alive
|
|
778
737
|
|
|
@@ -782,49 +741,37 @@ class CheeseAPI:
|
|
|
782
741
|
|
|
783
742
|
@property
|
|
784
743
|
def keep_alive_max_requests(self) -> int:
|
|
785
|
-
'''
|
|
786
|
-
长连接最大请求次数
|
|
787
|
-
'''
|
|
744
|
+
''' 长连接最大请求次数 '''
|
|
788
745
|
|
|
789
746
|
return self._keep_alive_max_requests
|
|
790
747
|
|
|
791
748
|
@property
|
|
792
749
|
def AppProxy_Class(self) -> Type[AppProxy]:
|
|
793
|
-
'''
|
|
794
|
-
若想要对底层逻辑进行处理,可传入自定义的 AppProxy 类
|
|
795
|
-
'''
|
|
750
|
+
''' 若想要对底层逻辑进行处理,可传入自定义的 AppProxy 类 '''
|
|
796
751
|
|
|
797
752
|
return self._AppProxy_Class
|
|
798
753
|
|
|
799
754
|
@property
|
|
800
755
|
def RequestProxy_Class(self) -> Type[RequestProxy]:
|
|
801
|
-
'''
|
|
802
|
-
若想要对请求处理逻辑进行处理,可传入自定义的 RequestProxy 类
|
|
803
|
-
'''
|
|
756
|
+
''' 若想要对请求处理逻辑进行处理,可传入自定义的 RequestProxy 类 '''
|
|
804
757
|
|
|
805
758
|
return self._RequestProxy_Class
|
|
806
759
|
|
|
807
760
|
@property
|
|
808
761
|
def ResponseProxy_Class(self) -> Type[ResponseProxy]:
|
|
809
|
-
'''
|
|
810
|
-
若想要对响应处理逻辑进行处理,可传入自定义的 ResponseProxy 类
|
|
811
|
-
'''
|
|
762
|
+
''' 若想要对响应处理逻辑进行处理,可传入自定义的 ResponseProxy 类 '''
|
|
812
763
|
|
|
813
764
|
return self._ResponseProxy_Class
|
|
814
765
|
|
|
815
766
|
@property
|
|
816
767
|
def RouteProxy_Class(self) -> Type[RouteProxy]:
|
|
817
|
-
'''
|
|
818
|
-
若想要对路由处理逻辑进行处理,可传入自定义的 RouteProxy 类
|
|
819
|
-
'''
|
|
768
|
+
''' 若想要对路由处理逻辑进行处理,可传入自定义的 RouteProxy 类 '''
|
|
820
769
|
|
|
821
770
|
return self._RouteProxy_Class
|
|
822
771
|
|
|
823
772
|
@property
|
|
824
773
|
def route(self) -> AppRoute:
|
|
825
|
-
'''
|
|
826
|
-
总路由
|
|
827
|
-
'''
|
|
774
|
+
''' 总路由 '''
|
|
828
775
|
|
|
829
776
|
return self._route
|
|
830
777
|
|
|
@@ -834,32 +781,24 @@ class CheeseAPI:
|
|
|
834
781
|
|
|
835
782
|
@property
|
|
836
783
|
def WebsocketProxy_Class(self) -> Type[WebsocketProxy]:
|
|
837
|
-
'''
|
|
838
|
-
若想要对 Websocket 处理逻辑进行处理,可传入自定义的 WebsocketProxy 类
|
|
839
|
-
'''
|
|
784
|
+
''' 若想要对 Websocket 处理逻辑进行处理,可传入自定义的 WebsocketProxy 类 '''
|
|
840
785
|
|
|
841
786
|
return self._WebsocketProxy_Class
|
|
842
787
|
|
|
843
788
|
@property
|
|
844
789
|
def scheduler(self) -> 'Scheduler':
|
|
845
|
-
'''
|
|
846
|
-
任务调度
|
|
847
|
-
'''
|
|
790
|
+
''' 任务调度 '''
|
|
848
791
|
|
|
849
792
|
return self._scheduler
|
|
850
793
|
|
|
851
794
|
@property
|
|
852
795
|
def SchedulerProxy_Class(self) -> Type[SchedulerProxy]:
|
|
853
|
-
'''
|
|
854
|
-
自定义任务调度器代理类
|
|
855
|
-
'''
|
|
796
|
+
''' 自定义任务调度器代理类 '''
|
|
856
797
|
|
|
857
798
|
return self._SchedulerProxy_Class
|
|
858
799
|
|
|
859
800
|
@property
|
|
860
801
|
def sync_server_timeout(self) -> float:
|
|
861
|
-
'''
|
|
862
|
-
同步服务器操作超时时间
|
|
863
|
-
'''
|
|
802
|
+
''' 同步服务器操作超时时间 '''
|
|
864
803
|
|
|
865
804
|
return self._sync_server_timeout
|
|
@@ -48,9 +48,7 @@ class Request:
|
|
|
48
48
|
return await self._proxy.recv_body(get_all = get_all)
|
|
49
49
|
|
|
50
50
|
async def parse_body(self):
|
|
51
|
-
'''
|
|
52
|
-
若在路由中设置了 `auto_recv_body = False`,则需要手动调用此方法解析请求体
|
|
53
|
-
'''
|
|
51
|
+
''' 若在路由中设置了 `auto_recv_body = False`,则需要手动调用此方法解析请求体 '''
|
|
54
52
|
|
|
55
53
|
await self._proxy.parse_body()
|
|
56
54
|
|
|
@@ -137,9 +137,7 @@ class Route:
|
|
|
137
137
|
|
|
138
138
|
@property
|
|
139
139
|
def path(self) -> str:
|
|
140
|
-
'''
|
|
141
|
-
路由前缀
|
|
142
|
-
'''
|
|
140
|
+
''' 路由前缀 '''
|
|
143
141
|
|
|
144
142
|
return self._path
|
|
145
143
|
|
|
@@ -179,17 +177,13 @@ class AppRoute(Route):
|
|
|
179
177
|
|
|
180
178
|
@property
|
|
181
179
|
def patterns(self) -> list[Pattern]:
|
|
182
|
-
'''
|
|
183
|
-
动态路由匹配模式
|
|
184
|
-
'''
|
|
180
|
+
''' 动态路由匹配模式 '''
|
|
185
181
|
|
|
186
182
|
return self._patterns
|
|
187
183
|
|
|
188
184
|
@property
|
|
189
185
|
def routes(self) -> dict[str, dict[HTTP_METHOD_TYPE, RouteDict]]:
|
|
190
|
-
'''
|
|
191
|
-
所有路由
|
|
192
|
-
'''
|
|
186
|
+
''' 所有路由 '''
|
|
193
187
|
|
|
194
188
|
return self._routes
|
|
195
189
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import inspect
|
|
1
2
|
import datetime, uuid, threading, multiprocessing, asyncio, time, json
|
|
2
3
|
from typing import Callable, Literal, TYPE_CHECKING
|
|
3
4
|
|
|
@@ -39,7 +40,7 @@ class Task:
|
|
|
39
40
|
- expected_run_num: 预期执行次数,若未设置则无限次执行
|
|
40
41
|
- key: 默认为随机 uuid
|
|
41
42
|
- run_type: 任务执行方式,可选线程、协程、进程
|
|
42
|
-
-
|
|
43
|
+
- kwargs: 自动包含 `app: CheeseAPI`,如果不提供 app 参数位置,则不会传入
|
|
43
44
|
- auto_remove: 任务完成期望次数后是否自动移除
|
|
44
45
|
- timeout: 当 app.sync_server_url 存在时,任务超过多少秒没有执行完毕则认为执行失败,在 sync_server 中会视为任务删除,None 默认为 interval_time * 2 的值;恢复执行后会在 sync_server 上自动恢复
|
|
45
46
|
'''
|
|
@@ -55,8 +56,8 @@ class Task:
|
|
|
55
56
|
self.run_type: Literal['THREAD', 'PROCESS', 'ASYNC'] = run_type
|
|
56
57
|
''' 任务执行方式,可选线程、协程、进程 '''
|
|
57
58
|
self.args: tuple = args
|
|
58
|
-
''' 默认首位是 `app: CheeseAPI` '''
|
|
59
59
|
self.kwargs: dict = kwargs
|
|
60
|
+
''' 自动包含 `app: CheeseAPI`,如果不提供 app 参数位置,则不会传入 '''
|
|
60
61
|
self.auto_remove: bool = auto_remove
|
|
61
62
|
''' 任务完成期望次数后是否自动移除 '''
|
|
62
63
|
self.timeout: float = timeout if timeout is not None else interval_time * 2
|
|
@@ -108,33 +109,25 @@ class Task:
|
|
|
108
109
|
|
|
109
110
|
@property
|
|
110
111
|
def last_run_timer(self) -> datetime.datetime | None:
|
|
111
|
-
'''
|
|
112
|
-
上一次的运行时刻
|
|
113
|
-
'''
|
|
112
|
+
''' 上一次的运行时刻 '''
|
|
114
113
|
|
|
115
114
|
return self._last_run_timer
|
|
116
115
|
|
|
117
116
|
@property
|
|
118
117
|
def last_run_time(self) -> float | None:
|
|
119
|
-
'''
|
|
120
|
-
上一次的运行耗时
|
|
121
|
-
'''
|
|
118
|
+
''' 上一次的运行耗时 '''
|
|
122
119
|
|
|
123
120
|
return self._last_run_time
|
|
124
121
|
|
|
125
122
|
@property
|
|
126
123
|
def run_num(self) -> int:
|
|
127
|
-
'''
|
|
128
|
-
运行次数
|
|
129
|
-
'''
|
|
124
|
+
''' 运行次数 '''
|
|
130
125
|
|
|
131
126
|
return self._run_num
|
|
132
127
|
|
|
133
128
|
@property
|
|
134
129
|
def is_running(self) -> bool:
|
|
135
|
-
'''
|
|
136
|
-
任务是否在运行中
|
|
137
|
-
'''
|
|
130
|
+
''' 任务是否在运行中 '''
|
|
138
131
|
|
|
139
132
|
return not self._queue.qsize()
|
|
140
133
|
|
|
@@ -154,7 +147,7 @@ class Scheduler:
|
|
|
154
147
|
- expected_run_num: 预期执行次数,若未设置则无限次执行
|
|
155
148
|
- key: 默认为 uuid
|
|
156
149
|
- run_type: 任务执行方式,可选线程、进程
|
|
157
|
-
-
|
|
150
|
+
- kwargs: 自动包含 `app: CheeseAPI`,如果不提供 app 参数位置,则不会传入
|
|
158
151
|
- auto_remove: 任务完成期望次数后是否自动移除
|
|
159
152
|
- timeout: 当 app.sync_server_url 存在时,任务超过多少秒没有执行完毕则认为执行失败,在 sync_server 中会视为任务删除,None 默认为 interval_time * 2 的值;恢复执行后会在 sync_server 上自动恢复
|
|
160
153
|
'''
|
|
@@ -172,7 +165,7 @@ class Scheduler:
|
|
|
172
165
|
- first_run_timer: 首次执行时间,若值小于当前时间则立刻执行
|
|
173
166
|
- expected_run_num: 预期执行次数,若未设置则无限次执行
|
|
174
167
|
- key: 默认为 uuid
|
|
175
|
-
-
|
|
168
|
+
- kwargs: 自动包含 `app: CheeseAPI`,如果不提供 app 参数位置,则不会传入
|
|
176
169
|
- auto_remove: 任务完成期望次数后是否自动移除
|
|
177
170
|
- timeout: 当 app.sync_server_url 存在时,任务超过多少秒没有执行完毕则认为执行失败,在 sync_server 中会视为任务删除,None 默认为 interval_time * 2 的值;恢复执行后会在 sync_server 上自动恢复
|
|
178
171
|
'''
|
|
@@ -180,72 +173,53 @@ class Scheduler:
|
|
|
180
173
|
return await self._proxy.async_add(interval_time, fn, first_run_timer = first_run_timer, expected_run_num = expected_run_num, key = key, args = args, kwargs = kwargs, auto_remove = auto_remove, timeout = timeout)
|
|
181
174
|
|
|
182
175
|
def start(self, key: str):
|
|
183
|
-
'''
|
|
184
|
-
启动任务
|
|
185
|
-
'''
|
|
176
|
+
''' 启动任务 '''
|
|
186
177
|
|
|
187
178
|
self._proxy.start(key)
|
|
188
179
|
|
|
189
180
|
async def async_start(self, key: str):
|
|
190
|
-
'''
|
|
191
|
-
启动任务
|
|
192
|
-
'''
|
|
181
|
+
''' 启动任务 '''
|
|
193
182
|
|
|
194
183
|
await self._proxy.async_start(key)
|
|
195
184
|
|
|
196
185
|
def stop(self, key: str):
|
|
197
|
-
'''
|
|
198
|
-
|
|
199
|
-
'''
|
|
186
|
+
''' 停止任务 '''
|
|
187
|
+
|
|
200
188
|
|
|
201
189
|
self._proxy.stop(key)
|
|
202
190
|
|
|
203
191
|
def remove(self, key: str):
|
|
204
|
-
'''
|
|
205
|
-
移除任务
|
|
206
|
-
'''
|
|
192
|
+
''' 移除任务 '''
|
|
207
193
|
|
|
208
194
|
self._proxy.remove(key)
|
|
209
195
|
|
|
210
196
|
async def async_stop(self, key: str):
|
|
211
|
-
'''
|
|
212
|
-
停止任务
|
|
213
|
-
'''
|
|
197
|
+
''' 停止任务 '''
|
|
214
198
|
|
|
215
199
|
await self._proxy.async_stop(key)
|
|
216
200
|
|
|
217
201
|
async def async_remove(self, key: str):
|
|
218
|
-
'''
|
|
219
|
-
移除任务
|
|
220
|
-
'''
|
|
202
|
+
''' 移除任务 '''
|
|
221
203
|
|
|
222
204
|
await self._proxy.async_remove(key)
|
|
223
205
|
|
|
224
206
|
def get_tasks(self) -> dict[str, Task]:
|
|
225
|
-
'''
|
|
226
|
-
获取所有任务
|
|
227
|
-
'''
|
|
207
|
+
''' 获取所有任务 '''
|
|
228
208
|
|
|
229
209
|
return self._proxy.get_tasks()
|
|
230
210
|
|
|
231
211
|
async def async_get_tasks(self) -> dict[str, Task]:
|
|
232
|
-
'''
|
|
233
|
-
获取所有任务
|
|
234
|
-
'''
|
|
212
|
+
''' 获取所有任务 '''
|
|
235
213
|
|
|
236
214
|
return await self._proxy.async_get_tasks()
|
|
237
215
|
|
|
238
216
|
def get_task(self, key: str) -> Task | None:
|
|
239
|
-
'''
|
|
240
|
-
获取任务
|
|
241
|
-
'''
|
|
217
|
+
''' 获取任务 '''
|
|
242
218
|
|
|
243
219
|
return self._proxy.get_task(key)
|
|
244
220
|
|
|
245
221
|
async def async_get_task(self, key: str) -> Task | None:
|
|
246
|
-
'''
|
|
247
|
-
获取任务
|
|
248
|
-
'''
|
|
222
|
+
''' 获取任务 '''
|
|
249
223
|
|
|
250
224
|
return await self._proxy.async_get_task(key)
|
|
251
225
|
|
|
@@ -398,7 +372,10 @@ class SchedulerProxy:
|
|
|
398
372
|
now = time.time()
|
|
399
373
|
|
|
400
374
|
try:
|
|
401
|
-
|
|
375
|
+
if 'app' in inspect.signature(fn).parameters:
|
|
376
|
+
fn(*args, app = self.app, **kwargs)
|
|
377
|
+
else:
|
|
378
|
+
fn(*args, **kwargs)
|
|
402
379
|
except Exception as e:
|
|
403
380
|
self.app.printer.scheduler_error(e, task)
|
|
404
381
|
|
|
@@ -451,7 +428,10 @@ class SchedulerProxy:
|
|
|
451
428
|
now = time.time()
|
|
452
429
|
|
|
453
430
|
try:
|
|
454
|
-
|
|
431
|
+
if 'app' in inspect.signature(fn).parameters:
|
|
432
|
+
await fn(*args, app = self.app, **kwargs)
|
|
433
|
+
else:
|
|
434
|
+
await fn(*args, **kwargs)
|
|
455
435
|
except Exception as e:
|
|
456
436
|
self.app.printer.scheduler_error(e, task)
|
|
457
437
|
|
|
@@ -477,7 +457,7 @@ class SchedulerProxy:
|
|
|
477
457
|
await asyncio.sleep(max(0, task.interval_time - time.time() + now))
|
|
478
458
|
|
|
479
459
|
if not task or task.auto_remove:
|
|
480
|
-
self._tasks.pop(
|
|
460
|
+
self._tasks.pop(key, None)
|
|
481
461
|
if static.scheduler_sync_servers is not None:
|
|
482
462
|
await redis.asyncio.Redis(connection_pool = static.scheduler_sync_servers[1]).hdel('CheeseAPI_scheduler_tasks', key)
|
|
483
463
|
else:
|
|
@@ -544,10 +524,8 @@ class SchedulerProxy:
|
|
|
544
524
|
|
|
545
525
|
def remove(self, key: str):
|
|
546
526
|
task = self.get_task(key)
|
|
547
|
-
if not task:
|
|
548
|
-
|
|
549
|
-
if not task.is_running:
|
|
550
|
-
raise KeyError(f'Task with key "{key}" is not running')
|
|
527
|
+
if not task or not task.is_running:
|
|
528
|
+
return
|
|
551
529
|
|
|
552
530
|
_task = self._tasks.get(key)
|
|
553
531
|
if not _task:
|
|
@@ -576,10 +554,8 @@ class SchedulerProxy:
|
|
|
576
554
|
|
|
577
555
|
async def async_remove(self, key: str):
|
|
578
556
|
task = await self.async_get_task(key)
|
|
579
|
-
if not task:
|
|
580
|
-
|
|
581
|
-
if not task.is_running:
|
|
582
|
-
raise KeyError(f'Task with key "{key}" is remove')
|
|
557
|
+
if not task or not task.is_running:
|
|
558
|
+
return
|
|
583
559
|
|
|
584
560
|
_task = self._tasks.get(key)
|
|
585
561
|
if not _task:
|
|
@@ -36,33 +36,25 @@ class Signal:
|
|
|
36
36
|
|
|
37
37
|
@property
|
|
38
38
|
def before_load_module(self) -> CheeseSignal:
|
|
39
|
-
'''
|
|
40
|
-
绑定函数`def func(*, index: int, module: str)`
|
|
41
|
-
'''
|
|
39
|
+
''' 绑定函数`def func(*, index: int, module: str)` '''
|
|
42
40
|
|
|
43
41
|
return self._before_load_module
|
|
44
42
|
|
|
45
43
|
@property
|
|
46
44
|
def after_load_module(self) -> CheeseSignal:
|
|
47
|
-
'''
|
|
48
|
-
绑定函数`def func(*, index: int, module: str)`
|
|
49
|
-
'''
|
|
45
|
+
''' 绑定函数`def func(*, index: int, module: str)` '''
|
|
50
46
|
|
|
51
47
|
return self._after_load_module
|
|
52
48
|
|
|
53
49
|
@property
|
|
54
50
|
def before_load_modules(self) -> CheeseSignal:
|
|
55
|
-
'''
|
|
56
|
-
绑定函数`def func(*, modules: list[str])`
|
|
57
|
-
'''
|
|
51
|
+
''' 绑定函数`def func(*, modules: list[str])` '''
|
|
58
52
|
|
|
59
53
|
return self._before_load_modules
|
|
60
54
|
|
|
61
55
|
@property
|
|
62
56
|
def after_load_modules(self) -> CheeseSignal:
|
|
63
|
-
'''
|
|
64
|
-
绑定函数`def func(*, modules: list[str])`
|
|
65
|
-
'''
|
|
57
|
+
''' 绑定函数`def func(*, modules: list[str])` '''
|
|
66
58
|
|
|
67
59
|
return self._after_load_modules
|
|
68
60
|
|
|
@@ -84,80 +76,60 @@ class Signal:
|
|
|
84
76
|
|
|
85
77
|
@property
|
|
86
78
|
def before_workers_start(self) -> CheeseSignal:
|
|
87
|
-
'''
|
|
88
|
-
绑定函数`def func(*, workers: int)`
|
|
89
|
-
'''
|
|
79
|
+
''' 绑定函数`def func(*, workers: int)` '''
|
|
90
80
|
|
|
91
81
|
return self._before_workers_start
|
|
92
82
|
|
|
93
83
|
@property
|
|
94
84
|
def after_workers_start(self) -> CheeseSignal:
|
|
95
|
-
'''
|
|
96
|
-
绑定函数`def func(*, workers: int)`
|
|
97
|
-
'''
|
|
85
|
+
''' 绑定函数`def func(*, workers: int)` '''
|
|
98
86
|
|
|
99
87
|
return self._after_workers_start
|
|
100
88
|
|
|
101
89
|
@property
|
|
102
90
|
def before_worker_start(self) -> CheeseSignal:
|
|
103
|
-
'''
|
|
104
|
-
绑定函数`def func(*, is_first: bool)`
|
|
105
|
-
'''
|
|
91
|
+
''' 绑定函数`def func(*, is_first: bool)` '''
|
|
106
92
|
|
|
107
93
|
return self._before_worker_start
|
|
108
94
|
|
|
109
95
|
@property
|
|
110
96
|
def after_worker_start(self) -> CheeseSignal:
|
|
111
|
-
'''
|
|
112
|
-
绑定协程函数`async def func(*, is_first: bool)`
|
|
113
|
-
'''
|
|
97
|
+
''' 绑定协程函数`async def func(*, is_first: bool)` '''
|
|
114
98
|
|
|
115
99
|
return self._after_worker_start
|
|
116
100
|
|
|
117
101
|
@property
|
|
118
102
|
def before_worker_stop(self) -> CheeseSignal:
|
|
119
|
-
'''
|
|
120
|
-
绑定协程函数`async def func(*, is_first: bool)`
|
|
121
|
-
'''
|
|
103
|
+
''' 绑定协程函数`async def func(*, is_first: bool)` '''
|
|
122
104
|
|
|
123
105
|
return self._before_worker_stop
|
|
124
106
|
|
|
125
107
|
@property
|
|
126
108
|
def after_worker_stop(self) -> CheeseSignal:
|
|
127
|
-
'''
|
|
128
|
-
绑定函数`def func(*, is_first: bool)`
|
|
129
|
-
'''
|
|
109
|
+
''' 绑定函数`def func(*, is_first: bool)` '''
|
|
130
110
|
|
|
131
111
|
return self._after_worker_stop
|
|
132
112
|
|
|
133
113
|
@property
|
|
134
114
|
def before_request(self) -> CheeseSignal:
|
|
135
|
-
'''
|
|
136
|
-
绑定协程函数`async def func(*, client_socket: socket.socket, addr: tuple[str, int])`
|
|
137
|
-
'''
|
|
115
|
+
''' 绑定协程函数`async def func(*, client_socket: socket.socket, addr: tuple[str, int])` '''
|
|
138
116
|
|
|
139
117
|
return self._before_request
|
|
140
118
|
|
|
141
119
|
@property
|
|
142
120
|
def after_request(self) -> CheeseSignal:
|
|
143
|
-
'''
|
|
144
|
-
绑定协程函数`async def func(*, request: Request | None)`
|
|
145
|
-
'''
|
|
121
|
+
''' 绑定协程函数`async def func(*, request: Request | None)` '''
|
|
146
122
|
|
|
147
123
|
return self._after_request
|
|
148
124
|
|
|
149
125
|
@property
|
|
150
126
|
def before_response(self) -> CheeseSignal:
|
|
151
|
-
'''
|
|
152
|
-
绑定协程函数`async def func(*, response: Response) -> Response`
|
|
153
|
-
'''
|
|
127
|
+
''' 绑定协程函数`async def func(*, response: Response) -> Response` '''
|
|
154
128
|
|
|
155
129
|
return self._before_response
|
|
156
130
|
|
|
157
131
|
@property
|
|
158
132
|
def after_response(self) -> CheeseSignal:
|
|
159
|
-
'''
|
|
160
|
-
绑定协程函数`async def func(*, response: Response)`
|
|
161
|
-
'''
|
|
133
|
+
''' 绑定协程函数`async def func(*, response: Response)` '''
|
|
162
134
|
|
|
163
135
|
return self._after_response
|
|
@@ -210,7 +210,7 @@ class WebsocketProxy:
|
|
|
210
210
|
await self.message()
|
|
211
211
|
await self.disconnect()
|
|
212
212
|
except Exception as e:
|
|
213
|
-
await self.app.printer.websocket_error(self.websocket
|
|
213
|
+
await self.app.printer.websocket_error(e, self.websocket)
|
|
214
214
|
|
|
215
215
|
async def get_response(self) -> Response:
|
|
216
216
|
headers = {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|