jaseci 1.4.2.6__py3-none-any.whl → 2.0.0__py3-none-any.whl

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.

Potentially problematic release.


This version of jaseci might be problematic. Click here for more details.

Files changed (187) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -118
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -77
  16. jaseci/extens/act_lib/file_handler.py +0 -190
  17. jaseci/extens/act_lib/internal.py +0 -19
  18. jaseci/extens/act_lib/jaseci.py +0 -62
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -192
  22. jaseci/extens/act_lib/rand.py +0 -83
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -170
  25. jaseci/extens/act_lib/std.py +0 -236
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -338
  28. jaseci/extens/act_lib/task.py +0 -14
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -80
  46. jaseci/extens/act_lib/vector.py +0 -158
  47. jaseci/extens/act_lib/webtool.py +0 -29
  48. jaseci/extens/act_lib/zip.py +0 -34
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -171
  51. jaseci/extens/api/alias_api.py +0 -140
  52. jaseci/extens/api/architype_api.py +0 -197
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -85
  55. jaseci/extens/api/graph_api.py +0 -168
  56. jaseci/extens/api/health_api.py +0 -21
  57. jaseci/extens/api/interface.py +0 -269
  58. jaseci/extens/api/jac_api.py +0 -172
  59. jaseci/extens/api/jsorc_api.py +0 -317
  60. jaseci/extens/api/logger_api.py +0 -90
  61. jaseci/extens/api/master_api.py +0 -134
  62. jaseci/extens/api/object_api.py +0 -102
  63. jaseci/extens/api/prometheus_api.py +0 -75
  64. jaseci/extens/api/queue_api.py +0 -141
  65. jaseci/extens/api/sentinel_api.py +0 -271
  66. jaseci/extens/api/share_api.py +0 -64
  67. jaseci/extens/api/super_api.py +0 -65
  68. jaseci/extens/api/tests/__init__.py +0 -0
  69. jaseci/extens/api/tests/test_architype_api.py +0 -66
  70. jaseci/extens/api/tests/test_global_api.py +0 -179
  71. jaseci/extens/api/tests/test_graph_api.py +0 -64
  72. jaseci/extens/api/tests/test_logger_api.py +0 -43
  73. jaseci/extens/api/tests/test_object_api.py +0 -20
  74. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  75. jaseci/extens/api/tests/test_uncommon.py +0 -107
  76. jaseci/extens/api/tests/test_user_api.py +0 -32
  77. jaseci/extens/api/tests/test_walker_api.py +0 -316
  78. jaseci/extens/api/user_api.py +0 -166
  79. jaseci/extens/api/walker_api.py +0 -299
  80. jaseci/extens/api/webhook_api.py +0 -77
  81. jaseci/extens/svc/__init__.py +0 -0
  82. jaseci/extens/svc/elastic_svc.py +0 -366
  83. jaseci/extens/svc/kube_svc.py +0 -432
  84. jaseci/extens/svc/mail_svc.py +0 -156
  85. jaseci/extens/svc/prome_svc.py +0 -378
  86. jaseci/extens/svc/redis_svc.py +0 -63
  87. jaseci/extens/svc/storage_svc.py +0 -193
  88. jaseci/extens/svc/stripe_svc.py +0 -51
  89. jaseci/extens/svc/task_svc.py +0 -155
  90. jaseci/extens/svc/tasks.py +0 -302
  91. jaseci/jac/__init__.py +0 -0
  92. jaseci/jac/interpreter/__init__.py +0 -0
  93. jaseci/jac/interpreter/architype_interp.py +0 -219
  94. jaseci/jac/interpreter/interp.py +0 -1784
  95. jaseci/jac/interpreter/sentinel_interp.py +0 -260
  96. jaseci/jac/interpreter/tests/__init__.py +0 -0
  97. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  98. jaseci/jac/interpreter/walker_interp.py +0 -249
  99. jaseci/jac/ir/__init__.py +0 -0
  100. jaseci/jac/ir/ast.py +0 -73
  101. jaseci/jac/ir/ast_builder.py +0 -249
  102. jaseci/jac/ir/jac_code.py +0 -151
  103. jaseci/jac/ir/passes/__init__.py +0 -6
  104. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  105. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  106. jaseci/jac/ir/passes/ir_pass.py +0 -29
  107. jaseci/jac/ir/passes/printer_pass.py +0 -23
  108. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  109. jaseci/jac/ir/passes/schedule.py +0 -23
  110. jaseci/jac/ir/passes/stats_pass.py +0 -16
  111. jaseci/jac/jac.g4 +0 -450
  112. jaseci/jac/jac_parse/__init__.py +0 -0
  113. jaseci/jac/jac_parse/jacLexer.py +0 -809
  114. jaseci/jac/jac_parse/jacListener.py +0 -853
  115. jaseci/jac/jac_parse/jacParser.py +0 -9192
  116. jaseci/jac/jac_set.py +0 -120
  117. jaseci/jac/jsci_vm/__init__.py +0 -0
  118. jaseci/jac/jsci_vm/disasm.py +0 -94
  119. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  120. jaseci/jac/jsci_vm/machine.py +0 -188
  121. jaseci/jac/jsci_vm/op_codes.py +0 -82
  122. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  123. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  124. jaseci/jac/machine/__init__.py +0 -0
  125. jaseci/jac/machine/jac_scope.py +0 -86
  126. jaseci/jac/machine/jac_value.py +0 -227
  127. jaseci/jac/machine/machine_state.py +0 -386
  128. jaseci/jac/tests/__init__.py +0 -0
  129. jaseci/jac/tests/book_code.py +0 -624
  130. jaseci/jac/tests/test_book.py +0 -380
  131. jaseci/jac/tests/test_lang_14.py +0 -49
  132. jaseci/jsorc/__init__.py +0 -7
  133. jaseci/jsorc/jsorc.py +0 -642
  134. jaseci/jsorc/jsorc_settings.py +0 -211
  135. jaseci/jsorc/jsorc_utils.py +0 -298
  136. jaseci/jsorc/live_actions.py +0 -365
  137. jaseci/jsorc/manifests/__init__.py +0 -0
  138. jaseci/jsorc/manifests/database.yaml +0 -109
  139. jaseci/jsorc/manifests/elastic.yaml +0 -6029
  140. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  141. jaseci/jsorc/manifests/redis.yaml +0 -64
  142. jaseci/jsorc/memory.py +0 -258
  143. jaseci/jsorc/redis.py +0 -140
  144. jaseci/jsorc/remote_actions.py +0 -158
  145. jaseci/jsorc/tests/__init__.py +0 -0
  146. jaseci/jsorc/tests/test_actions.py +0 -542
  147. jaseci/jsorc/tests/test_jsorc.py +0 -112
  148. jaseci/prim/__init__.py +0 -0
  149. jaseci/prim/ability.py +0 -94
  150. jaseci/prim/architype.py +0 -90
  151. jaseci/prim/edge.py +0 -173
  152. jaseci/prim/element.py +0 -233
  153. jaseci/prim/graph.py +0 -27
  154. jaseci/prim/master.py +0 -67
  155. jaseci/prim/node.py +0 -533
  156. jaseci/prim/obj_mixins.py +0 -238
  157. jaseci/prim/sentinel.py +0 -282
  158. jaseci/prim/super_master.py +0 -31
  159. jaseci/prim/walker.py +0 -261
  160. jaseci/svc/__init__.py +0 -0
  161. jaseci/tests/__init__.py +0 -0
  162. jaseci/tests/infer.py +0 -39
  163. jaseci/tests/jac_test_code.py +0 -1293
  164. jaseci/tests/jac_test_progs.py +0 -774
  165. jaseci/tests/test_core.py +0 -153
  166. jaseci/tests/test_jac.py +0 -824
  167. jaseci/tests/test_node.py +0 -89
  168. jaseci/tests/test_progs.py +0 -702
  169. jaseci/tests/test_stack.py +0 -220
  170. jaseci/tests/test_stripe.py +0 -225
  171. jaseci/utils/__init__.py +0 -0
  172. jaseci/utils/actions/__init__.py +0 -0
  173. jaseci/utils/actions/actions_manager.py +0 -254
  174. jaseci/utils/actions/actions_optimizer.py +0 -517
  175. jaseci/utils/actions/actions_state.py +0 -95
  176. jaseci/utils/file_handler.py +0 -171
  177. jaseci/utils/gprof2dot.py +0 -3786
  178. jaseci/utils/id_list.py +0 -169
  179. jaseci/utils/json_handler.py +0 -70
  180. jaseci/utils/log_utils.py +0 -57
  181. jaseci/utils/test_core.py +0 -62
  182. jaseci/utils/utils.py +0 -387
  183. jaseci-1.4.2.6.dist-info/LICENSE +0 -21
  184. jaseci-1.4.2.6.dist-info/METADATA +0 -39
  185. jaseci-1.4.2.6.dist-info/RECORD +0 -185
  186. jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
  187. jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
@@ -1,64 +0,0 @@
1
- apiVersion: v1
2
- kind: Service
3
- metadata:
4
- name: jaseci-redis
5
- namespace: redis
6
- spec:
7
- selector:
8
- pod: jaseci-redis
9
- ports:
10
- - protocol: TCP
11
- port: 6379
12
- targetPort: 6379
13
- ---
14
- apiVersion: apps/v1
15
- kind: Deployment
16
- metadata:
17
- name: jaseci-redis
18
- namespace: redis
19
- spec:
20
- replicas: 1
21
- selector:
22
- matchLabels:
23
- pod: jaseci-redis
24
- template:
25
- metadata:
26
- labels:
27
- pod: jaseci-redis
28
- spec:
29
- containers:
30
- - name: jaseci-redis-master
31
- image: redis
32
- imagePullPolicy: IfNotPresent
33
- command:
34
- - redis-server
35
- - "/redis-master/redis.conf"
36
- resources:
37
- limits:
38
- cpu: "0.2"
39
- ports:
40
- - containerPort: 6379
41
- volumeMounts:
42
- - mountPath: /redis-master-data
43
- name: data
44
- - mountPath: /redis-master
45
- name: config
46
- volumes:
47
- - name: data
48
- emptyDir: {}
49
- - name: config
50
- configMap:
51
- name: jaseci-redis-config
52
- items:
53
- - key: redis-config
54
- path: redis.conf
55
- ---
56
- apiVersion: v1
57
- kind: ConfigMap
58
- metadata:
59
- name: jaseci-redis-config
60
- namespace: redis
61
- data:
62
- redis-config: |
63
- maxmemory 1000mb
64
- maxmemory-policy allkeys-lru
jaseci/jsorc/memory.py DELETED
@@ -1,258 +0,0 @@
1
- from json import dumps, loads
2
- import sys
3
- from jaseci.utils.file_handler import FileHandler
4
- from jaseci.utils.utils import find_class_and_import
5
- from jaseci.jsorc.jsorc import JsOrc
6
-
7
-
8
- @JsOrc.repository(name="hook")
9
- class MemoryHook:
10
- """
11
- Set of virtual functions to be used as hooks to allow access to
12
- the complete set of items across jaseci object types. This class contains
13
- a number of blank function calls to be bound extrenally and passed
14
- to the objects. They return jaseci core types.
15
- """
16
-
17
- def __init__(self):
18
- from jaseci.jsorc.live_actions import get_global_actions
19
-
20
- self.mem = {"global": {}}
21
- self._machine = None
22
- self.save_obj_list = set()
23
- self.save_glob_dict = {}
24
- self.file_handlers = {}
25
-
26
- ####################################################
27
- # COMMON GETTER/SETTER #
28
- ####################################################
29
-
30
- # --------------------- OBJ ---------------------- #
31
-
32
- def get_obj(self, caller_id, item_id, override=False):
33
- """
34
- Get item from session cache by id, then try store
35
- TODO: May need to make this an object copy so you cant do mem writes
36
- """
37
- ret = self.get_obj_from_store(item_id)
38
- if override or (ret is not None and ret.check_read_access(caller_id)):
39
- return ret
40
-
41
- def has_obj(self, item_id):
42
- """
43
- Checks for object existance
44
- """
45
- return self.has_obj_in_store(item_id)
46
-
47
- def save_obj(self, caller_id, item, all_caches=False):
48
- """Save item to session cache, then to store"""
49
- if item.check_write_access(caller_id):
50
- self.commit_obj_to_cache(item, all_caches=all_caches)
51
- if item._persist:
52
- self.save_obj_list.add(item)
53
-
54
- def destroy_obj(self, caller_id, item):
55
- """Destroy item from session cache then store"""
56
- if item.check_write_access(caller_id):
57
- self.decommit_obj_from_cache(item)
58
- if item._persist:
59
- self.destroy_obj_from_store(item)
60
-
61
- # --------------------- GLOB --------------------- #
62
-
63
- def get_glob(self, name):
64
- """
65
- Get global config from session cache by id, then try store
66
- """
67
- return self.get_glob_from_store(name)
68
-
69
- def has_glob(self, name):
70
- """
71
- Checks for global config existance
72
- """
73
- return self.has_glob_in_store(name)
74
-
75
- def resolve_glob(self, name, default=None):
76
- """
77
- Util function for returning config if exists otherwise default
78
- """
79
- if self.has_glob(name):
80
- return self.get_glob(name)
81
- else:
82
- return default
83
-
84
- def save_glob(self, name, value, persist=True):
85
- """Save global config to session cache, then to store"""
86
- self.commit_glob_to_cache(name, value)
87
-
88
- if persist:
89
- self.save_glob_dict[name] = value
90
-
91
- def list_glob(self):
92
- """Lists all configs present"""
93
- return self.list_glob_from_store()
94
-
95
- def destroy_glob(self, name, persist=True):
96
- """Destroy global config from session cache then store"""
97
- self.decommit_glob_from_cache(name)
98
-
99
- if persist:
100
- self.destroy_glob_from_store(name)
101
-
102
- # ----------------- SERVICE GLOB ----------------- #
103
-
104
- def get_or_create_glob(self, name, val):
105
- if not self.has_glob(name):
106
- self.save_glob(name, dumps(val))
107
- self.commit()
108
- return loads(self.get_glob(name))
109
-
110
- ####################################################
111
- # DATASOURCE METHOD (TO BE OVERRIDE) #
112
- ####################################################
113
-
114
- # --------------------- OBJ ---------------------- #
115
-
116
- def get_obj_from_store(self, item_id):
117
- """
118
- Get item from externally hooked general store by id
119
- """
120
- if item_id in self.mem:
121
- return self.mem[item_id]
122
-
123
- return None
124
-
125
- def has_obj_in_store(self, item_id):
126
- """
127
- Checks for object existance in store
128
- """
129
- return item_id in self.mem
130
-
131
- def destroy_obj_from_store(self, item):
132
- """Destroy item to externally hooked general store"""
133
- if item in self.save_obj_list:
134
- self.save_obj_list.remove(item)
135
-
136
- # --------------------- GLOB --------------------- #
137
-
138
- def get_glob_from_store(self, name):
139
- """
140
- Get global config from externally hooked general store by name
141
- """
142
- if name in self.mem["global"]:
143
- return self.mem["global"][name]
144
-
145
- return None
146
-
147
- def has_glob_in_store(self, name):
148
- """
149
- Checks for global config existance in store
150
- """
151
- return name in self.mem["global"]
152
-
153
- def destroy_glob_from_store(self, name):
154
- """Destroy global config to externally hooked general store"""
155
- if name in self.save_glob_dict:
156
- self.save_glob_dict.pop(name)
157
-
158
- def list_glob_from_store(self):
159
- """Get list of global config to externally hooked general store"""
160
- return list(self.mem["global"].keys())
161
-
162
- ####################################################
163
- # ------------------ COMMITTER ------------------- #
164
- ####################################################
165
-
166
- def commit(self, skip_cache=False):
167
- if not skip_cache:
168
- for i in self.save_obj_list:
169
- self.commit_obj_to_cache(i)
170
-
171
- self.save_obj_list = set()
172
-
173
- for i in self.save_glob_dict.keys():
174
- self.commit_glob_to_cache(name=i, value=self.save_glob_dict[i])
175
-
176
- self.save_glob_dict = {}
177
-
178
- ###################################################
179
- # CACHE CONTROL (SHOULD NOT OVERRIDEN ON ORM) #
180
- ###################################################
181
-
182
- # -------------------- GLOBS -------------------- #
183
-
184
- def commit_glob_to_cache(self, name, value):
185
- self.mem["global"][name] = value
186
-
187
- def decommit_glob_from_cache(self, name):
188
- self.mem["global"].pop(name)
189
-
190
- # --------------------- OBJ --------------------- #
191
-
192
- def has_id_in_mem_cache(self, id):
193
- return id is not None and id in self.mem
194
-
195
- def commit_obj_to_cache(self, item, all_caches=False):
196
- self.mem[item.jid] = item
197
-
198
- def commit_all_cache_sync(self):
199
- for i in self.save_obj_list:
200
- self.commit_obj_to_cache(i, all_caches=True)
201
-
202
- def decommit_obj_from_cache(self, item):
203
- self.mem.pop(item.jid)
204
-
205
- ####################################################
206
- # ------------------ UTILITIES ------------------- #
207
- ####################################################
208
-
209
- def get_object_distribution(self):
210
- dist = {}
211
- for i in self.mem.keys():
212
- t = type(self.mem[i])
213
- if t in dist.keys():
214
- dist[t] += 1
215
- else:
216
- dist[t] = 1
217
- return dist
218
-
219
- def mem_size(self):
220
- return sys.getsizeof(self.mem) / 1024
221
-
222
- ###################################################
223
- # CLASS CONTROL #
224
- ###################################################
225
-
226
- def find_class_and_import(self, j_type, mod):
227
- cls = JsOrc.ctx_cls(j_type)
228
-
229
- if not cls:
230
- cls = find_class_and_import(j_type, mod)
231
-
232
- return cls
233
-
234
- def clear_cache(self, all=False):
235
- MemoryHook.__init__(self)
236
-
237
- ####################################################
238
- # FILE HANDLER #
239
- ####################################################
240
-
241
- def add_file_handler(self, file_handler: FileHandler) -> str:
242
- self.file_handlers.update({file_handler.id: file_handler})
243
- return file_handler.id
244
-
245
- def get_file_handler(self, file_id: str):
246
- return self.file_handlers.get(file_id, None)
247
-
248
- def pop_file_handler(self, file_id: str):
249
- return self.file_handlers.pop(file_id, None)
250
-
251
- def clean_file_handler(self):
252
- for file_handler in list(self.file_handlers.values()):
253
- self.file_handlers.pop(file_handler.id, None)
254
- if not file_handler.persist:
255
- file_handler.delete()
256
-
257
- def __del__(self):
258
- self.clean_file_handler()
jaseci/jsorc/redis.py DELETED
@@ -1,140 +0,0 @@
1
- """
2
- This module includes code related to hooking Jaseci's Redis to the
3
- core engine.
4
- """
5
-
6
- import json
7
-
8
- import jaseci as core_mod
9
- from jaseci.utils.json_handler import JaseciJsonDecoder, jsci_dict_normalize
10
- from jaseci.jsorc.memory import MemoryHook
11
- from jaseci.jsorc.jsorc import JsOrc
12
- from jaseci.extens.svc.redis_svc import RedisService
13
-
14
-
15
- #################################################
16
- # REDIS HOOK #
17
- #################################################
18
-
19
-
20
- @JsOrc.repository(name="hook", priority=1)
21
- class RedisHook(MemoryHook):
22
- def __init__(self, redis: RedisService = None):
23
- self.redis = JsOrc.svc("redis", RedisService)
24
- self.red_touch_count = 0
25
-
26
- super().__init__()
27
-
28
- ####################################################
29
- # DATASOURCE METHOD (TO BE OVERRIDE) #
30
- ####################################################
31
-
32
- # --------------------- OBJ ---------------------- #
33
-
34
- def get_obj_from_store(self, item_id):
35
- """
36
- Get item from externally hooked general store by id
37
- """
38
- obj = super().get_obj_from_store(item_id)
39
-
40
- if obj is None and self.redis.is_running():
41
- loaded_obj = self.redis.get(item_id)
42
- if loaded_obj:
43
- self.red_touch_count += 1
44
- jdict = json.loads(loaded_obj, cls=JaseciJsonDecoder)
45
- j_type = jdict["j_type"]
46
- j_master = jdict["j_master"]
47
- class_for_type = self.find_class_and_import(j_type, core_mod)
48
- ret_obj = class_for_type(h=self, m_id=j_master, auto_save=False)
49
- jsci_dict_normalize(jdict, parent_obj=ret_obj)
50
- ret_obj.dict_load(jdict)
51
-
52
- super().commit_obj_to_cache(ret_obj)
53
- obj = ret_obj
54
- if obj:
55
- obj._persist = True
56
- return obj
57
-
58
- def has_obj_in_store(self, item_id):
59
- """
60
- Checks for object existance in store
61
- """
62
- return super().has_obj_in_store(item_id) or (
63
- self.redis.is_running() and self.redis.exists(item_id)
64
- )
65
-
66
- # --------------------- GLOB --------------------- #
67
-
68
- def get_glob_from_store(self, name):
69
- """
70
- Get global config from externally hooked general store by name
71
- """
72
- glob = super().get_glob_from_store(name)
73
-
74
- if glob is None and self.redis.is_running():
75
- glob = self.redis.hget("global", name)
76
-
77
- if glob:
78
- self.red_touch_count += 1
79
- super().commit_glob_to_cache(name, glob)
80
-
81
- return glob
82
-
83
- def has_glob_in_store(self, name):
84
- """
85
- Checks for global config existance in store
86
- """
87
- return super().has_glob_in_store(name) or (
88
- self.redis.is_running() and self.redis.hexists("global", name)
89
- )
90
-
91
- def list_glob_from_store(self):
92
- """Get list of global config to externally hooked general store"""
93
- globs = super().list_glob_from_store()
94
-
95
- if not globs and self.redis.is_running():
96
- globs = self.redis.hkeys("global")
97
-
98
- return globs
99
-
100
- ###################################################
101
- # CACHE CONTROL (SHOULD NOT OVERRIDEN ON ORM) #
102
- ###################################################
103
-
104
- # -------------------- GLOBS -------------------- #
105
-
106
- def commit_glob_to_cache(self, name, value):
107
- super().commit_glob_to_cache(name, value)
108
- if self.redis.is_running():
109
- self.redis.hset("global", name, value)
110
-
111
- def decommit_glob_from_cache(self, name):
112
- super().decommit_glob_from_cache(name)
113
-
114
- if self.redis.is_running():
115
- self.redis.hdel("global", name)
116
-
117
- # --------------------- OBJ --------------------- #
118
-
119
- def commit_obj_to_cache(self, item, all_caches=False):
120
- super().commit_obj_to_cache(item)
121
-
122
- if all_caches and item._persist and self.redis.is_running():
123
- self.redis.set(item.jid, item.json(detailed=True))
124
-
125
- def decommit_obj_from_cache(self, item):
126
- super().decommit_obj_from_cache(item)
127
-
128
- if item._persist and self.redis.is_running():
129
- self.redis.delete(item.jid)
130
-
131
- ###################################################
132
- # CLEANER #
133
- ###################################################
134
-
135
- def clear_cache(self, all=False):
136
- super().clear_cache(all)
137
- self.redis.clear(all)
138
-
139
-
140
- # ----------------------------------------------- #
@@ -1,158 +0,0 @@
1
- """
2
- General action base class with automation for hot loading
3
- """
4
-
5
- from jaseci.utils.utils import logger, ColCodes as Cc
6
- from fastapi import FastAPI
7
- from fastapi.responses import RedirectResponse
8
- from pydantic import validate_arguments
9
- from time import time
10
- import inspect
11
- import uvicorn
12
- import os
13
- import re
14
-
15
- var_args = re.compile(r"^\*[^\*]")
16
- var_kwargs = re.compile(r"^\*\*[^\*]")
17
-
18
- args_kwargs = (2, 4)
19
- remote_actions = {}
20
- registered_apis = []
21
- registered_endpoints = []
22
- ACTIONS_SPEC_LOC = "/jaseci_actions_spec/"
23
- JS_ACTION_PREAMBLE = "js_action_"
24
- JS_ENDPOINT_PREAMBLE = "js_endpoint_"
25
-
26
-
27
- def mark_as_remote(api):
28
- registered_apis.append(api)
29
-
30
-
31
- def mark_as_endpoint(endpoint):
32
- registered_endpoints.append(endpoint)
33
-
34
-
35
- def serv_actions():
36
- """Returns fastAPI app interface for actions"""
37
- app = FastAPI(
38
- title="Jaseci Action Set API",
39
- description="A Jaseci Action Set",
40
- )
41
-
42
- @app.get("/")
43
- def home_redirect():
44
- return RedirectResponse(url="/docs")
45
-
46
- @app.get(ACTIONS_SPEC_LOC)
47
- def action_list():
48
- return remote_actions
49
-
50
- for i in registered_apis:
51
- gen_api_service(app, *i)
52
- for i in registered_endpoints:
53
- gen_endpoint(app, *i)
54
- return app
55
-
56
-
57
- def gen_api_service(app, func, act_group, aliases, caller_globals):
58
- """Helper for jaseci_action decorator"""
59
- # Construct list of action apis available
60
- act_group = (
61
- [os.path.basename(inspect.getfile(func)).split(".")[0]]
62
- if act_group is None
63
- else act_group
64
- )
65
- varnames = []
66
- for param in inspect.signature(func).parameters.values():
67
- varnames.append(str(param) if param.kind in args_kwargs else param.name)
68
-
69
- remote_actions[f"{'.'.join(act_group+[func.__name__])}"] = varnames
70
-
71
- # Need to get pydatic model for func signature for fastAPI post
72
- model = validate_arguments(func).model
73
-
74
- # Keep only fields present in param list in base model
75
- keep_fields = {}
76
- for name in varnames:
77
- if var_args.match(name):
78
- keep_fields[name] = model.__fields__[name[1:]]
79
- keep_fields[name].name = name
80
- keep_fields[name].alias = name
81
- elif var_kwargs.match(name):
82
- keep_fields[name] = model.__fields__[name[2:]]
83
- keep_fields[name].name = name
84
- keep_fields[name].alias = name
85
- else:
86
- field = model.__fields__.get(name)
87
- if field:
88
- keep_fields[name] = field
89
- model.__fields__ = keep_fields
90
-
91
- # Create duplicate funtion for api endpoint and inject in call site globals
92
- @app.post(f"/{func.__name__}/")
93
- def new_func(params: model = model.construct()):
94
- params: dict = params.__dict__
95
- pl_peek = str(params)[:128]
96
- logger.info(str(f"Incoming call to {func.__name__} with {pl_peek}"))
97
- start_time = time()
98
-
99
- args = []
100
- kwargs = {}
101
- fp1 = inspect.signature(func).parameters.values()
102
- fp2 = list(fp1)
103
-
104
- # try to process args
105
- for param in fp1:
106
- _param = str(param) if param.kind in args_kwargs else param.name
107
- if _param in params:
108
- fp2.remove(param)
109
- if var_args.match(_param):
110
- for arg in params.get(_param) or []:
111
- args.append(arg)
112
- break
113
- elif var_kwargs.match(_param):
114
- kwargs.update(params.get(_param) or {})
115
- break
116
- args.append(params.get(_param))
117
- else:
118
- break
119
-
120
- # try to process kwargs
121
- for param in fp2:
122
- param = str(param) if param.kind in args_kwargs else param.name
123
- if param in params:
124
- if var_kwargs.match(param):
125
- kwargs.update(params.get(param) or {})
126
- break
127
- kwargs[param] = params.get(param)
128
- else:
129
- break
130
-
131
- ret = validate_arguments(func)(*args, **kwargs)
132
- tot_time = time() - start_time
133
- logger.info(
134
- str(
135
- f"API call to {Cc.TG}{func.__name__}{Cc.EC}"
136
- f" completed in {Cc.TY}{tot_time:.3f} seconds{Cc.EC}"
137
- )
138
- )
139
- return ret
140
-
141
- if func.__name__ == "setup":
142
- new_func = app.on_event("startup")(new_func)
143
- for i in aliases:
144
- new_func = app.post(f"/{i}/")(new_func)
145
- remote_actions[f"{'.'.join(act_group+[i])}"] = varnames
146
- caller_globals[f"{JS_ACTION_PREAMBLE}{func.__name__}"] = new_func
147
-
148
-
149
- def gen_endpoint(app, func, endpoint, mount, caller_globals):
150
- """Helper for jaseci_action decorator"""
151
- # Create duplicate funtion for api endpoint and inject in call site globals
152
- if mount is not None:
153
- app.mount(*mount)
154
- caller_globals[f"{JS_ENDPOINT_PREAMBLE}{func.__name__}"] = app.get(endpoint)(func)
155
-
156
-
157
- def launch_server(port=80, host="0.0.0.0"):
158
- uvicorn.run(serv_actions(), port=port, host=host)
File without changes