jaseci 1.4.0.19__py3-none-any.whl → 1.4.0.20__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.

jaseci/jsorc/jsorc.py CHANGED
@@ -47,6 +47,7 @@ class JsOrc:
47
47
 
48
48
  # ------------------ COMMONS ------------------ #
49
49
 
50
+ _config = None
50
51
  _backoff_interval = 10
51
52
  _running_interval = 0
52
53
  __running__ = False
@@ -68,16 +69,23 @@ class JsOrc:
68
69
  key=lambda item: (-item["priority"], -item["date_added"]),
69
70
  )
70
71
 
72
+ @classmethod
73
+ def configure(cls):
74
+ config: dict = cls.settings("JSORC_CONFIG")
75
+
76
+ if cls.db_check():
77
+ hook = cls.hook()
78
+ config = hook.get_or_create_glob("JSORC_CONFIG", config)
79
+
80
+ cls._config = config
81
+ cls._backoff_interval = max(5, config.get("backoff_interval", 10))
82
+ cls._regeneration_queues = config.get("pre_loaded_services", [])
83
+
71
84
  @classmethod
72
85
  def run(cls):
73
86
  if not cls.__running__:
74
87
  cls.__running__ == True
75
- config: dict = cls.settings("JSORC_CONFIG")
76
- if cls.db_check():
77
- hook = cls.hook()
78
- config = hook.get_or_create_glob("JSORC_CONFIG", config)
79
- cls._backoff_interval = max(5, config.get("backoff_interval", 10))
80
- cls._regeneration_queues = config.get("pre_loaded_services", [])
88
+ cls.configure()
81
89
  cls.push_interval(1)
82
90
 
83
91
  @classmethod
@@ -466,87 +474,92 @@ class JsOrc:
466
474
  from jaseci.utils.actions.actions_manager import ActionManager
467
475
 
468
476
  kube = cls.svc("kube", KubeService)
469
- while cls._regeneration_queues:
470
- regeneration_queue = cls._regeneration_queues.pop(0)
477
+ regeneration_queues = cls._regeneration_queues.copy()
478
+ cls._regeneration_queues.clear()
479
+ while regeneration_queues:
480
+ regeneration_queue = regeneration_queues.pop(0)
471
481
  service = cls.svc(regeneration_queue)
472
482
  hook = cls.hook(use_proxy=service.source["proxy"])
473
483
  if not service.is_running() and service.enabled and service.automated:
474
484
  if service.manifest and kube.is_running():
475
- manifest = kube.resolve_manifest(
476
- hook.get_or_create_glob(
477
- service.source["manifest"], service.manifest
478
- ),
479
- *cls.overrided_namespace(
480
- regeneration_queue, service.manifest_type
481
- ),
482
- )
483
-
484
- rmhists: dict = hook.get_or_create_glob(
485
- "RESOLVED_MANIFEST_HISTORY", {}
486
- )
487
-
488
- _rmhist = rmhists.get(service.source["manifest"], [{}])[0]
489
- rmhist = deepcopy(_rmhist)
490
-
491
- for kind, confs in manifest.items():
492
- for name, conf in confs.items():
493
- namespace = conf["metadata"].get("namespace")
485
+ try:
486
+ manifest = kube.resolve_manifest(
487
+ hook.get_or_create_glob(
488
+ service.source["manifest"], service.manifest
489
+ ),
490
+ *cls.overrided_namespace(
491
+ regeneration_queue, service.manifest_type
492
+ ),
493
+ )
494
+
495
+ rmhists: dict = hook.get_or_create_glob(
496
+ "RESOLVED_MANIFEST_HISTORY", {}
497
+ )
498
+
499
+ _rmhist = rmhists.get(service.source["manifest"], [{}])[0]
500
+ rmhist = deepcopy(_rmhist)
501
+
502
+ for kind, confs in manifest.items():
503
+ for name, conf in confs.items():
504
+ namespace = conf["metadata"].get("namespace")
505
+
506
+ if kind in rmhist and name in rmhist[kind]:
507
+ rmhist[kind].pop(name, None)
508
+
509
+ res = kube.read(kind, name, namespace)
510
+ if hasattr(res, "status") and res.status == 404:
511
+ kube.create(kind, name, conf, namespace)
512
+ elif not isinstance(res, ApiException):
513
+ config_version = 1
514
+
515
+ if isinstance(res, dict):
516
+ if "labels" in res["metadata"]:
517
+ config_version = (
518
+ res["metadata"]
519
+ .get("labels", {})
520
+ .get("config_version", 1)
521
+ )
522
+ elif res.metadata.labels:
523
+ config_version = res.metadata.labels.get(
524
+ "config_version", 1
525
+ )
494
526
 
495
- if kind in rmhist and name in rmhist[kind]:
496
- rmhist[kind].pop(name, None)
527
+ if config_version != conf.get("metadata").get(
528
+ "labels", {}
529
+ ).get("config_version", 1):
530
+ kube.patch(kind, name, conf, namespace)
531
+
532
+ for kind, confs in rmhist.items():
533
+ for name, conf in confs.items():
534
+ namespace = conf["metadata"].get("namespace")
535
+ res = kube.read(kind, name, namespace, quiet=True)
536
+ if not isinstance(res, ApiException) and (
537
+ (isinstance(res, dict) and res.get("metadata"))
538
+ or res.metadata
539
+ ):
540
+ if kind not in cls.settings(
541
+ "UNSAFE_KINDS"
542
+ ) or service.manifest_unsafe_paraphrase == cls.settings(
543
+ "UNSAFE_PARAPHRASE"
544
+ ):
545
+ kube.delete(kind, name, namespace)
546
+ else:
547
+ logger.info(
548
+ f"You don't have permission to delete `{kind}` for `{name}` with namespace `{namespace}`!"
549
+ )
497
550
 
498
- res = kube.read(kind, name, namespace)
499
- if hasattr(res, "status") and res.status == 404:
500
- kube.create(kind, name, conf, namespace)
501
- elif not isinstance(res, ApiException):
502
- config_version = 1
551
+ if _rmhist != manifest:
552
+ if service.source["manifest"] not in rmhists:
553
+ rmhists[service.source["manifest"]] = [manifest]
554
+ else:
555
+ rmhists[service.source["manifest"]].insert(0, manifest)
556
+ hook.save_glob("RESOLVED_MANIFEST_HISTORY", dumps(rmhists))
557
+ hook.commit()
503
558
 
504
- if isinstance(res, dict):
505
- if "labels" in res["metadata"]:
506
- config_version = (
507
- res["metadata"]
508
- .get("labels", {})
509
- .get("config_version", 1)
510
- )
511
- elif res.metadata.labels:
512
- config_version = res.metadata.labels.get(
513
- "config_version", 1
514
- )
515
-
516
- if config_version != conf.get("metadata").get(
517
- "labels", {}
518
- ).get("config_version", 1):
519
- kube.patch(kind, name, conf, namespace)
520
-
521
- for kind, confs in rmhist.items():
522
- for name, conf in confs.items():
523
- namespace = conf["metadata"].get("namespace")
524
- res = kube.read(kind, name, namespace, quiet=True)
525
- if not isinstance(res, ApiException) and (
526
- (isinstance(res, dict) and res.get("metadata"))
527
- or res.metadata
528
- ):
529
- if kind not in cls.settings(
530
- "UNSAFE_KINDS"
531
- ) or service.manifest_unsafe_paraphrase == cls.settings(
532
- "UNSAFE_PARAPHRASE"
533
- ):
534
- kube.delete(kind, name, namespace)
535
- else:
536
- logger.info(
537
- f"You don't have permission to delete `{kind}` for `{name}` with namespace `{namespace}`!"
538
- )
539
-
540
- if _rmhist != manifest:
541
- if service.source["manifest"] not in rmhists:
542
- rmhists[service.source["manifest"]] = [manifest]
543
- else:
544
- rmhists[service.source["manifest"]].insert(0, manifest)
545
- hook.save_glob("RESOLVED_MANIFEST_HISTORY", dumps(rmhists))
546
- hook.commit()
559
+ except Exception as e:
560
+ logger.error(f"Unhandled exception: {e}")
547
561
 
548
562
  cls.svc_reset(regeneration_queue)
549
- sleep(1)
550
563
 
551
564
  action_manager = cls.get("action_manager", ActionManager)
552
565
  action_manager.optimize(jsorc_interval=cls._backoff_interval)
@@ -247,6 +247,7 @@ def get_global_actions():
247
247
  h=glob_act_hook,
248
248
  mode="public",
249
249
  name=i,
250
+ kind="ability",
250
251
  value=i,
251
252
  persist=False,
252
253
  )
jaseci/prim/ability.py CHANGED
@@ -27,7 +27,7 @@ class Ability(Element, JacCode, Interp):
27
27
  self.preset_in_out = preset_in_out # Not using _ids convention
28
28
  self.access_list = access_list
29
29
  Element.__init__(self, *args, **kwargs)
30
- JacCode.__init__(self, code_ir)
30
+ JacCode.__init__(self, code_ir=code_ir)
31
31
  Interp.__init__(self)
32
32
 
33
33
  def run_ability(self, here, visitor):
@@ -35,7 +35,15 @@ class Ability(Element, JacCode, Interp):
35
35
  Run ability
36
36
  """
37
37
  Interp.__init__(self) # Reset before as result need to be absorbed after
38
- self.push_scope(JacScope(parent=self, has_obj=here, here=here, visitor=visitor))
38
+ self.push_scope(
39
+ JacScope(
40
+ parent=self,
41
+ name=f"a_run:{self.get_jac_ast().loc_str()}",
42
+ has_obj=here,
43
+ here=here,
44
+ visitor=visitor,
45
+ )
46
+ )
39
47
  self.run_code_block(self.get_jac_ast())
40
48
  self.pop_scope()
41
49
 
jaseci/prim/sentinel.py CHANGED
@@ -219,7 +219,9 @@ class Sentinel(Element, JacCode, SentinelInterp):
219
219
  if i["assert_block"]:
220
220
  wlk._loop_ctrl = None
221
221
  wlk.scope_and_run(
222
- jac_ir_to_ast(i["assert_block"]), run_func=wlk.run_code_block
222
+ jac_ir_to_ast(i["assert_block"]),
223
+ run_func=wlk.run_code_block,
224
+ scope_name="assert_block",
223
225
  )
224
226
  i["passed"] = True
225
227
  if not silent:
jaseci/prim/walker.py CHANGED
@@ -10,7 +10,6 @@ from jaseci.utils.utils import (
10
10
  logger,
11
11
  perf_test_start,
12
12
  perf_test_stop,
13
- perf_test_to_dot,
14
13
  exc_stack_as_str_list,
15
14
  )
16
15
  from jaseci.prim.element import Element
@@ -22,6 +21,7 @@ import hashlib
22
21
 
23
22
  from jaseci.jsorc.jsorc import JsOrc
24
23
  from jaseci.extens.svc.task_svc import TaskService
24
+ from jaseci.utils.utils import format_jac_profile
25
25
 
26
26
 
27
27
  class Walker(Element, WalkerInterp, Anchored):
@@ -191,8 +191,10 @@ class Walker(Element, WalkerInterp, Anchored):
191
191
  report_ret["errors"] = self.runtime_errors
192
192
  report_ret["success"] = False
193
193
  if profiling:
194
- self.profile["perf"] = perf_test_stop(pr)
195
- self.profile["graph"] = perf_test_to_dot(pr)
194
+ self.profile["jac"] = format_jac_profile(self.get_master()._jac_profile)
195
+ calls, graph = perf_test_stop(pr)
196
+ self.profile["perf"] = calls
197
+ self.profile["graph"] = graph
196
198
  report_ret["profile"] = self.profile
197
199
 
198
200
  if self.for_queue():
jaseci/tests/test_jac.py CHANGED
@@ -165,7 +165,7 @@ class JacTests(TestCaseHelper, TestCase):
165
165
  """Test preset function loading"""
166
166
  from jaseci.jac.machine.jac_scope import JacScope
167
167
 
168
- JacScope(None)
168
+ JacScope(None, None)
169
169
  from jaseci.jac.machine.jac_scope import get_global_actions
170
170
 
171
171
  self.assertGreater(len(get_global_actions()), 5)
@@ -206,3 +206,15 @@ class StackTests(CoreTest):
206
206
  self.assertIn("digraph", ret["profile"]["graph"])
207
207
  self.assertIn("jaseci", ret["profile"]["graph"])
208
208
  self.assertGreater(len(ret["profile"]["graph"]), 1000)
209
+
210
+ def test_jac_profiling_in_walker(self):
211
+ ret = self.call(
212
+ self.mast,
213
+ ["sentinel_register", {"code": self.load_jac("simple.jac")}],
214
+ )
215
+ ret = self.call(
216
+ self.mast, ["walker_run", {"name": "complex", "profiling": True}]
217
+ )
218
+ print(ret["profile"]["jac"])
219
+ self.assertIn("cum_time", ret["profile"]["jac"])
220
+ self.assertIn("run_walker", ret["profile"]["graph"])