jaseci 1.4.2.5__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 (186) 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.5.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 -117
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -76
  16. jaseci/extens/act_lib/file_handler.py +0 -189
  17. jaseci/extens/act_lib/internal.py +0 -18
  18. jaseci/extens/act_lib/jaseci.py +0 -61
  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 -191
  22. jaseci/extens/act_lib/rand.py +0 -82
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -169
  25. jaseci/extens/act_lib/std.py +0 -235
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -337
  28. jaseci/extens/act_lib/task.py +0 -13
  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 -79
  46. jaseci/extens/act_lib/vector.py +0 -157
  47. jaseci/extens/act_lib/webtool.py +0 -28
  48. jaseci/extens/act_lib/zip.py +0 -33
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -170
  51. jaseci/extens/api/alias_api.py +0 -139
  52. jaseci/extens/api/architype_api.py +0 -196
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -84
  55. jaseci/extens/api/graph_api.py +0 -167
  56. jaseci/extens/api/health_api.py +0 -20
  57. jaseci/extens/api/interface.py +0 -268
  58. jaseci/extens/api/jac_api.py +0 -171
  59. jaseci/extens/api/jsorc_api.py +0 -316
  60. jaseci/extens/api/logger_api.py +0 -89
  61. jaseci/extens/api/master_api.py +0 -133
  62. jaseci/extens/api/object_api.py +0 -101
  63. jaseci/extens/api/prometheus_api.py +0 -74
  64. jaseci/extens/api/queue_api.py +0 -140
  65. jaseci/extens/api/sentinel_api.py +0 -270
  66. jaseci/extens/api/super_api.py +0 -64
  67. jaseci/extens/api/tests/__init__.py +0 -0
  68. jaseci/extens/api/tests/test_architype_api.py +0 -66
  69. jaseci/extens/api/tests/test_global_api.py +0 -179
  70. jaseci/extens/api/tests/test_graph_api.py +0 -64
  71. jaseci/extens/api/tests/test_logger_api.py +0 -43
  72. jaseci/extens/api/tests/test_object_api.py +0 -20
  73. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  74. jaseci/extens/api/tests/test_uncommon.py +0 -107
  75. jaseci/extens/api/tests/test_user_api.py +0 -32
  76. jaseci/extens/api/tests/test_walker_api.py +0 -316
  77. jaseci/extens/api/user_api.py +0 -144
  78. jaseci/extens/api/walker_api.py +0 -298
  79. jaseci/extens/api/webhook_api.py +0 -74
  80. jaseci/extens/svc/__init__.py +0 -0
  81. jaseci/extens/svc/elastic_svc.py +0 -366
  82. jaseci/extens/svc/kube_svc.py +0 -432
  83. jaseci/extens/svc/mail_svc.py +0 -156
  84. jaseci/extens/svc/prome_svc.py +0 -378
  85. jaseci/extens/svc/redis_svc.py +0 -63
  86. jaseci/extens/svc/storage_svc.py +0 -193
  87. jaseci/extens/svc/stripe_svc.py +0 -51
  88. jaseci/extens/svc/task_svc.py +0 -155
  89. jaseci/extens/svc/tasks.py +0 -302
  90. jaseci/jac/__init__.py +0 -0
  91. jaseci/jac/interpreter/__init__.py +0 -0
  92. jaseci/jac/interpreter/architype_interp.py +0 -214
  93. jaseci/jac/interpreter/interp.py +0 -1783
  94. jaseci/jac/interpreter/sentinel_interp.py +0 -257
  95. jaseci/jac/interpreter/tests/__init__.py +0 -0
  96. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  97. jaseci/jac/interpreter/walker_interp.py +0 -248
  98. jaseci/jac/ir/__init__.py +0 -0
  99. jaseci/jac/ir/ast.py +0 -73
  100. jaseci/jac/ir/ast_builder.py +0 -249
  101. jaseci/jac/ir/jac_code.py +0 -152
  102. jaseci/jac/ir/passes/__init__.py +0 -6
  103. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  104. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  105. jaseci/jac/ir/passes/ir_pass.py +0 -29
  106. jaseci/jac/ir/passes/printer_pass.py +0 -23
  107. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  108. jaseci/jac/ir/passes/schedule.py +0 -23
  109. jaseci/jac/ir/passes/stats_pass.py +0 -16
  110. jaseci/jac/jac.g4 +0 -450
  111. jaseci/jac/jac_parse/__init__.py +0 -0
  112. jaseci/jac/jac_parse/jacLexer.py +0 -809
  113. jaseci/jac/jac_parse/jacListener.py +0 -853
  114. jaseci/jac/jac_parse/jacParser.py +0 -9192
  115. jaseci/jac/jac_set.py +0 -119
  116. jaseci/jac/jsci_vm/__init__.py +0 -0
  117. jaseci/jac/jsci_vm/disasm.py +0 -94
  118. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  119. jaseci/jac/jsci_vm/machine.py +0 -188
  120. jaseci/jac/jsci_vm/op_codes.py +0 -82
  121. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  122. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  123. jaseci/jac/machine/__init__.py +0 -0
  124. jaseci/jac/machine/jac_scope.py +0 -85
  125. jaseci/jac/machine/jac_value.py +0 -226
  126. jaseci/jac/machine/machine_state.py +0 -383
  127. jaseci/jac/tests/__init__.py +0 -0
  128. jaseci/jac/tests/book_code.py +0 -624
  129. jaseci/jac/tests/test_book.py +0 -380
  130. jaseci/jac/tests/test_lang_14.py +0 -49
  131. jaseci/jsorc/__init__.py +0 -7
  132. jaseci/jsorc/jsorc.py +0 -642
  133. jaseci/jsorc/jsorc_settings.py +0 -211
  134. jaseci/jsorc/jsorc_utils.py +0 -298
  135. jaseci/jsorc/live_actions.py +0 -364
  136. jaseci/jsorc/manifests/__init__.py +0 -0
  137. jaseci/jsorc/manifests/database.yaml +0 -109
  138. jaseci/jsorc/manifests/elastic.yaml +0 -6024
  139. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  140. jaseci/jsorc/manifests/redis.yaml +0 -64
  141. jaseci/jsorc/memory.py +0 -258
  142. jaseci/jsorc/redis.py +0 -139
  143. jaseci/jsorc/remote_actions.py +0 -157
  144. jaseci/jsorc/tests/__init__.py +0 -0
  145. jaseci/jsorc/tests/test_actions.py +0 -542
  146. jaseci/jsorc/tests/test_jsorc.py +0 -112
  147. jaseci/prim/__init__.py +0 -0
  148. jaseci/prim/ability.py +0 -93
  149. jaseci/prim/architype.py +0 -89
  150. jaseci/prim/edge.py +0 -172
  151. jaseci/prim/element.py +0 -233
  152. jaseci/prim/graph.py +0 -26
  153. jaseci/prim/master.py +0 -64
  154. jaseci/prim/node.py +0 -532
  155. jaseci/prim/obj_mixins.py +0 -235
  156. jaseci/prim/sentinel.py +0 -281
  157. jaseci/prim/super_master.py +0 -31
  158. jaseci/prim/walker.py +0 -261
  159. jaseci/svc/__init__.py +0 -0
  160. jaseci/tests/__init__.py +0 -0
  161. jaseci/tests/infer.py +0 -39
  162. jaseci/tests/jac_test_code.py +0 -1293
  163. jaseci/tests/jac_test_progs.py +0 -774
  164. jaseci/tests/test_core.py +0 -153
  165. jaseci/tests/test_jac.py +0 -824
  166. jaseci/tests/test_node.py +0 -89
  167. jaseci/tests/test_progs.py +0 -702
  168. jaseci/tests/test_stack.py +0 -220
  169. jaseci/tests/test_stripe.py +0 -225
  170. jaseci/utils/__init__.py +0 -0
  171. jaseci/utils/actions/__init__.py +0 -0
  172. jaseci/utils/actions/actions_manager.py +0 -254
  173. jaseci/utils/actions/actions_optimizer.py +0 -516
  174. jaseci/utils/actions/actions_state.py +0 -95
  175. jaseci/utils/file_handler.py +0 -171
  176. jaseci/utils/gprof2dot.py +0 -3786
  177. jaseci/utils/id_list.py +0 -168
  178. jaseci/utils/json_handler.py +0 -70
  179. jaseci/utils/log_utils.py +0 -57
  180. jaseci/utils/test_core.py +0 -62
  181. jaseci/utils/utils.py +0 -387
  182. jaseci-1.4.2.5.dist-info/LICENSE +0 -21
  183. jaseci-1.4.2.5.dist-info/METADATA +0 -39
  184. jaseci-1.4.2.5.dist-info/RECORD +0 -184
  185. jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
  186. jaseci-1.4.2.5.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,139 +0,0 @@
1
- """
2
- This module includes code related to hooking Jaseci's Redis to the
3
- core engine.
4
- """
5
- import json
6
-
7
- import jaseci as core_mod
8
- from jaseci.utils.json_handler import JaseciJsonDecoder, jsci_dict_normalize
9
- from jaseci.jsorc.memory import MemoryHook
10
- from jaseci.jsorc.jsorc import JsOrc
11
- from jaseci.extens.svc.redis_svc import RedisService
12
-
13
-
14
- #################################################
15
- # REDIS HOOK #
16
- #################################################
17
-
18
-
19
- @JsOrc.repository(name="hook", priority=1)
20
- class RedisHook(MemoryHook):
21
- def __init__(self, redis: RedisService = None):
22
- self.redis = JsOrc.svc("redis", RedisService)
23
- self.red_touch_count = 0
24
-
25
- super().__init__()
26
-
27
- ####################################################
28
- # DATASOURCE METHOD (TO BE OVERRIDE) #
29
- ####################################################
30
-
31
- # --------------------- OBJ ---------------------- #
32
-
33
- def get_obj_from_store(self, item_id):
34
- """
35
- Get item from externally hooked general store by id
36
- """
37
- obj = super().get_obj_from_store(item_id)
38
-
39
- if obj is None and self.redis.is_running():
40
- loaded_obj = self.redis.get(item_id)
41
- if loaded_obj:
42
- self.red_touch_count += 1
43
- jdict = json.loads(loaded_obj, cls=JaseciJsonDecoder)
44
- j_type = jdict["j_type"]
45
- j_master = jdict["j_master"]
46
- class_for_type = self.find_class_and_import(j_type, core_mod)
47
- ret_obj = class_for_type(h=self, m_id=j_master, auto_save=False)
48
- jsci_dict_normalize(jdict, parent_obj=ret_obj)
49
- ret_obj.dict_load(jdict)
50
-
51
- super().commit_obj_to_cache(ret_obj)
52
- obj = ret_obj
53
- if obj:
54
- obj._persist = True
55
- return obj
56
-
57
- def has_obj_in_store(self, item_id):
58
- """
59
- Checks for object existance in store
60
- """
61
- return super().has_obj_in_store(item_id) or (
62
- self.redis.is_running() and self.redis.exists(item_id)
63
- )
64
-
65
- # --------------------- GLOB --------------------- #
66
-
67
- def get_glob_from_store(self, name):
68
- """
69
- Get global config from externally hooked general store by name
70
- """
71
- glob = super().get_glob_from_store(name)
72
-
73
- if glob is None and self.redis.is_running():
74
- glob = self.redis.hget("global", name)
75
-
76
- if glob:
77
- self.red_touch_count += 1
78
- super().commit_glob_to_cache(name, glob)
79
-
80
- return glob
81
-
82
- def has_glob_in_store(self, name):
83
- """
84
- Checks for global config existance in store
85
- """
86
- return super().has_glob_in_store(name) or (
87
- self.redis.is_running() and self.redis.hexists("global", name)
88
- )
89
-
90
- def list_glob_from_store(self):
91
- """Get list of global config to externally hooked general store"""
92
- globs = super().list_glob_from_store()
93
-
94
- if not globs and self.redis.is_running():
95
- globs = self.redis.hkeys("global")
96
-
97
- return globs
98
-
99
- ###################################################
100
- # CACHE CONTROL (SHOULD NOT OVERRIDEN ON ORM) #
101
- ###################################################
102
-
103
- # -------------------- GLOBS -------------------- #
104
-
105
- def commit_glob_to_cache(self, name, value):
106
- super().commit_glob_to_cache(name, value)
107
- if self.redis.is_running():
108
- self.redis.hset("global", name, value)
109
-
110
- def decommit_glob_from_cache(self, name):
111
- super().decommit_glob_from_cache(name)
112
-
113
- if self.redis.is_running():
114
- self.redis.hdel("global", name)
115
-
116
- # --------------------- OBJ --------------------- #
117
-
118
- def commit_obj_to_cache(self, item, all_caches=False):
119
- super().commit_obj_to_cache(item)
120
-
121
- if all_caches and item._persist and self.redis.is_running():
122
- self.redis.set(item.jid, item.json(detailed=True))
123
-
124
- def decommit_obj_from_cache(self, item):
125
- super().decommit_obj_from_cache(item)
126
-
127
- if item._persist and self.redis.is_running():
128
- self.redis.delete(item.jid)
129
-
130
- ###################################################
131
- # CLEANER #
132
- ###################################################
133
-
134
- def clear_cache(self, all=False):
135
- super().clear_cache(all)
136
- self.redis.clear(all)
137
-
138
-
139
- # ----------------------------------------------- #
@@ -1,157 +0,0 @@
1
- """
2
- General action base class with automation for hot loading
3
- """
4
- from jaseci.utils.utils import logger, ColCodes as Cc
5
- from fastapi import FastAPI
6
- from fastapi.responses import RedirectResponse
7
- from pydantic import validate_arguments
8
- from time import time
9
- import inspect
10
- import uvicorn
11
- import os
12
- import re
13
-
14
- var_args = re.compile(r"^\*[^\*]")
15
- var_kwargs = re.compile(r"^\*\*[^\*]")
16
-
17
- args_kwargs = (2, 4)
18
- remote_actions = {}
19
- registered_apis = []
20
- registered_endpoints = []
21
- ACTIONS_SPEC_LOC = "/jaseci_actions_spec/"
22
- JS_ACTION_PREAMBLE = "js_action_"
23
- JS_ENDPOINT_PREAMBLE = "js_endpoint_"
24
-
25
-
26
- def mark_as_remote(api):
27
- registered_apis.append(api)
28
-
29
-
30
- def mark_as_endpoint(endpoint):
31
- registered_endpoints.append(endpoint)
32
-
33
-
34
- def serv_actions():
35
- """Returns fastAPI app interface for actions"""
36
- app = FastAPI(
37
- title="Jaseci Action Set API",
38
- description="A Jaseci Action Set",
39
- )
40
-
41
- @app.get("/")
42
- def home_redirect():
43
- return RedirectResponse(url="/docs")
44
-
45
- @app.get(ACTIONS_SPEC_LOC)
46
- def action_list():
47
- return remote_actions
48
-
49
- for i in registered_apis:
50
- gen_api_service(app, *i)
51
- for i in registered_endpoints:
52
- gen_endpoint(app, *i)
53
- return app
54
-
55
-
56
- def gen_api_service(app, func, act_group, aliases, caller_globals):
57
- """Helper for jaseci_action decorator"""
58
- # Construct list of action apis available
59
- act_group = (
60
- [os.path.basename(inspect.getfile(func)).split(".")[0]]
61
- if act_group is None
62
- else act_group
63
- )
64
- varnames = []
65
- for param in inspect.signature(func).parameters.values():
66
- varnames.append(str(param) if param.kind in args_kwargs else param.name)
67
-
68
- remote_actions[f"{'.'.join(act_group+[func.__name__])}"] = varnames
69
-
70
- # Need to get pydatic model for func signature for fastAPI post
71
- model = validate_arguments(func).model
72
-
73
- # Keep only fields present in param list in base model
74
- keep_fields = {}
75
- for name in varnames:
76
- if var_args.match(name):
77
- keep_fields[name] = model.__fields__[name[1:]]
78
- keep_fields[name].name = name
79
- keep_fields[name].alias = name
80
- elif var_kwargs.match(name):
81
- keep_fields[name] = model.__fields__[name[2:]]
82
- keep_fields[name].name = name
83
- keep_fields[name].alias = name
84
- else:
85
- field = model.__fields__.get(name)
86
- if field:
87
- keep_fields[name] = field
88
- model.__fields__ = keep_fields
89
-
90
- # Create duplicate funtion for api endpoint and inject in call site globals
91
- @app.post(f"/{func.__name__}/")
92
- def new_func(params: model = model.construct()):
93
- params: dict = params.__dict__
94
- pl_peek = str(params)[:128]
95
- logger.info(str(f"Incoming call to {func.__name__} with {pl_peek}"))
96
- start_time = time()
97
-
98
- args = []
99
- kwargs = {}
100
- fp1 = inspect.signature(func).parameters.values()
101
- fp2 = list(fp1)
102
-
103
- # try to process args
104
- for param in fp1:
105
- _param = str(param) if param.kind in args_kwargs else param.name
106
- if _param in params:
107
- fp2.remove(param)
108
- if var_args.match(_param):
109
- for arg in params.get(_param) or []:
110
- args.append(arg)
111
- break
112
- elif var_kwargs.match(_param):
113
- kwargs.update(params.get(_param) or {})
114
- break
115
- args.append(params.get(_param))
116
- else:
117
- break
118
-
119
- # try to process kwargs
120
- for param in fp2:
121
- param = str(param) if param.kind in args_kwargs else param.name
122
- if param in params:
123
- if var_kwargs.match(param):
124
- kwargs.update(params.get(param) or {})
125
- break
126
- kwargs[param] = params.get(param)
127
- else:
128
- break
129
-
130
- ret = validate_arguments(func)(*args, **kwargs)
131
- tot_time = time() - start_time
132
- logger.info(
133
- str(
134
- f"API call to {Cc.TG}{func.__name__}{Cc.EC}"
135
- f" completed in {Cc.TY}{tot_time:.3f} seconds{Cc.EC}"
136
- )
137
- )
138
- return ret
139
-
140
- if func.__name__ == "setup":
141
- new_func = app.on_event("startup")(new_func)
142
- for i in aliases:
143
- new_func = app.post(f"/{i}/")(new_func)
144
- remote_actions[f"{'.'.join(act_group+[i])}"] = varnames
145
- caller_globals[f"{JS_ACTION_PREAMBLE}{func.__name__}"] = new_func
146
-
147
-
148
- def gen_endpoint(app, func, endpoint, mount, caller_globals):
149
- """Helper for jaseci_action decorator"""
150
- # Create duplicate funtion for api endpoint and inject in call site globals
151
- if mount is not None:
152
- app.mount(*mount)
153
- caller_globals[f"{JS_ENDPOINT_PREAMBLE}{func.__name__}"] = app.get(endpoint)(func)
154
-
155
-
156
- def launch_server(port=80, host="0.0.0.0"):
157
- uvicorn.run(serv_actions(), port=port, host=host)
File without changes