jaseci 1.4.0.9__py3-none-any.whl → 1.4.0.11__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/VERSION +1 -1
- jaseci/__init__.py +3 -0
- jaseci/actions/standard/elastic.py +3 -2
- jaseci/actions/standard/mail.py +3 -2
- jaseci/actions/standard/std.py +3 -2
- jaseci/actions/standard/stripe.py +3 -2
- jaseci/actions/standard/task.py +3 -5
- jaseci/actions/standard/tests/test_mail_lib.py +8 -7
- jaseci/actions/tests/test_std.py +4 -5
- jaseci/actor/walker.py +6 -3
- jaseci/api/config_api.py +3 -2
- jaseci/api/jac_api.py +2 -2
- jaseci/api/jsorc_api.py +60 -121
- jaseci/api/prometheus_api.py +14 -20
- jaseci/api/queue_api.py +9 -5
- jaseci/api/tests/test_global_api.py +3 -3
- jaseci/api/tests/test_logger_api.py +3 -3
- jaseci/api/user_api.py +3 -3
- jaseci/api/webhook_api.py +6 -4
- jaseci/attr/action.py +10 -4
- jaseci/element/master.py +2 -0
- jaseci/element/super_master.py +2 -0
- jaseci/hook/memory.py +3 -1
- jaseci/hook/redis.py +5 -4
- jaseci/jac/interpreter/interp.py +16 -4
- jaseci/jac/tests/test_book.py +2 -2
- jaseci/jsctl/jsctl.py +48 -15
- jaseci/jsctl/tests/test_jsctl.py +5 -0
- jaseci/jsorc.py +733 -0
- jaseci/jsorc_settings.py +184 -0
- jaseci/manifests/database.yaml +107 -0
- jaseci/manifests/elastic.yaml +5923 -0
- jaseci/manifests/prometheus.yaml +1273 -0
- jaseci/{svc/jsorc-backup/jaseci-redis.yaml → manifests/redis.yaml} +20 -0
- jaseci/svc/__init__.py +0 -25
- jaseci/svc/{elastic/elastic.py → elastic_svc.py} +5 -16
- jaseci/svc/kube_svc.py +240 -0
- jaseci/svc/{mail/mail.py → mail_svc.py} +14 -17
- jaseci/svc/{prometheus/prometheus.py → prome_svc.py} +5 -16
- jaseci/svc/{redis/redis.py → redis_svc.py} +14 -26
- jaseci/svc/{stripe/stripe.py → stripe_svc.py} +4 -7
- jaseci/svc/{task/task.py → task_svc.py} +27 -24
- jaseci/svc/{task/common.py → tasks.py} +287 -293
- jaseci/tests/jac_test_progs.py +21 -0
- jaseci/tests/test_core.py +14 -15
- jaseci/tests/test_jac.py +59 -60
- jaseci/tests/test_node.py +6 -13
- jaseci/tests/test_progs.py +74 -52
- jaseci/tests/test_stripe.py +6 -10
- jaseci/utils/actions/actions_manager.py +254 -0
- jaseci/{svc/actions_optimizer → utils/actions}/actions_optimizer.py +9 -19
- jaseci/utils/json_handler.py +2 -3
- jaseci/utils/test_core.py +4 -5
- jaseci/utils/utils.py +12 -0
- {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/METADATA +2 -1
- {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/RECORD +63 -80
- jaseci/svc/common.py +0 -763
- jaseci/svc/config.py +0 -9
- jaseci/svc/elastic/__init__.py +0 -3
- jaseci/svc/elastic/config.py +0 -8
- jaseci/svc/elastic/manifest.py +0 -1
- jaseci/svc/jsorc-backup/jsorc.py +0 -182
- jaseci/svc/jsorc-backup/promon/__init__.py +0 -0
- jaseci/svc/jsorc-backup/promon/promon.py +0 -202
- jaseci/svc/mail/__init__.py +0 -4
- jaseci/svc/mail/config.py +0 -25
- jaseci/svc/meta.py +0 -164
- jaseci/svc/postgres/__init__.py +0 -0
- jaseci/svc/postgres/manifest.py +0 -106
- jaseci/svc/prometheus/__init__.py +0 -5
- jaseci/svc/prometheus/config.py +0 -11
- jaseci/svc/prometheus/manifest.py +0 -1102
- jaseci/svc/redis/__init__.py +0 -5
- jaseci/svc/redis/config.py +0 -10
- jaseci/svc/redis/manifest.py +0 -65
- jaseci/svc/state.py +0 -17
- jaseci/svc/stripe/__init__.py +0 -3
- jaseci/svc/stripe/config.py +0 -7
- jaseci/svc/task/__init__.py +0 -5
- jaseci/svc/task/config.py +0 -17
- /jaseci/{svc/actions_optimizer → manifests}/__init__.py +0 -0
- /jaseci/{svc/jsorc-backup → utils/actions}/__init__.py +0 -0
- /jaseci/{svc/actions_optimizer → utils/actions}/actions_state.py +0 -0
- {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/LICENSE +0 -0
- {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/WHEEL +0 -0
- {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/entry_points.txt +0 -0
- {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/top_level.txt +0 -0
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
apiVersion: v1
|
|
2
|
+
kind: Service
|
|
3
|
+
metadata:
|
|
4
|
+
name: jaseci-redis
|
|
5
|
+
spec:
|
|
6
|
+
selector:
|
|
7
|
+
pod: jaseci-redis
|
|
8
|
+
ports:
|
|
9
|
+
- protocol: TCP
|
|
10
|
+
port: 6379
|
|
11
|
+
targetPort: 6379
|
|
1
12
|
---
|
|
2
13
|
apiVersion: apps/v1
|
|
3
14
|
kind: Deployment
|
|
@@ -39,3 +50,12 @@ spec:
|
|
|
39
50
|
items:
|
|
40
51
|
- key: redis-config
|
|
41
52
|
path: redis.conf
|
|
53
|
+
---
|
|
54
|
+
apiVersion: v1
|
|
55
|
+
kind: ConfigMap
|
|
56
|
+
metadata:
|
|
57
|
+
name: jaseci-redis-config
|
|
58
|
+
data:
|
|
59
|
+
redis-config: |
|
|
60
|
+
maxmemory 1000mb
|
|
61
|
+
maxmemory-policy allkeys-lru
|
jaseci/svc/__init__.py
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
from .state import ServiceState
|
|
2
|
-
from .common import CommonService, ProxyService, JsOrc, MetaProperties, Kube
|
|
3
|
-
from .redis import RedisService
|
|
4
|
-
from .task import TaskService
|
|
5
|
-
from .stripe import StripeService
|
|
6
|
-
from .mail import MailService
|
|
7
|
-
from .prometheus import PrometheusService
|
|
8
|
-
from .elastic import ElasticService
|
|
9
|
-
from .meta import MetaService
|
|
10
|
-
|
|
11
|
-
__all__ = [
|
|
12
|
-
"ServiceState",
|
|
13
|
-
"JsOrc",
|
|
14
|
-
"MetaProperties",
|
|
15
|
-
"CommonService",
|
|
16
|
-
"ProxyService",
|
|
17
|
-
"RedisService",
|
|
18
|
-
"TaskService",
|
|
19
|
-
"StripeService",
|
|
20
|
-
"MailService",
|
|
21
|
-
"PrometheusService",
|
|
22
|
-
"ElasticService",
|
|
23
|
-
"MetaService",
|
|
24
|
-
"Kube",
|
|
25
|
-
]
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
from jaseci
|
|
2
|
-
from .config import ELASTIC_CONFIG
|
|
3
|
-
from .manifest import ELASTIC_MANIFEST
|
|
1
|
+
from jaseci import JsOrc
|
|
4
2
|
from requests import get, post
|
|
5
3
|
from datetime import datetime
|
|
6
4
|
from copy import copy
|
|
@@ -11,28 +9,19 @@ from copy import copy
|
|
|
11
9
|
#################################################
|
|
12
10
|
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
@JsOrc.service(name="elastic", config="ELASTIC_CONFIG", manifest="ELASTIC_MANIFEST")
|
|
13
|
+
class ElasticService(JsOrc.CommonService):
|
|
15
14
|
###################################################
|
|
16
15
|
# BUILDER #
|
|
17
16
|
###################################################
|
|
18
17
|
|
|
19
|
-
def run(self
|
|
18
|
+
def run(self):
|
|
20
19
|
self.app = Elastic(self.config)
|
|
21
20
|
self.app.health("timeout=1s")
|
|
22
21
|
|
|
23
|
-
####################################################
|
|
24
|
-
# OVERRIDDEN #
|
|
25
|
-
####################################################
|
|
26
|
-
|
|
27
|
-
def build_config(self, hook) -> dict:
|
|
28
|
-
return hook.service_glob("ELASTIC_CONFIG", ELASTIC_CONFIG)
|
|
29
|
-
|
|
30
|
-
def build_manifest(self, hook) -> dict:
|
|
31
|
-
return hook.service_glob("ELASTIC_MANIFEST", ELASTIC_MANIFEST)
|
|
32
|
-
|
|
33
22
|
|
|
34
23
|
class Elastic:
|
|
35
|
-
def __init__(self, config):
|
|
24
|
+
def __init__(self, config: dict):
|
|
36
25
|
if not config.get("url"):
|
|
37
26
|
raise Exception("URL is required!")
|
|
38
27
|
self.url = config["url"]
|
jaseci/svc/kube_svc.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
from jaseci import JsOrc
|
|
2
|
+
|
|
3
|
+
from kubernetes import config as kubernetes_config
|
|
4
|
+
from kubernetes.client import (
|
|
5
|
+
ApiClient,
|
|
6
|
+
CoreV1Api,
|
|
7
|
+
AppsV1Api,
|
|
8
|
+
RbacAuthorizationV1Api,
|
|
9
|
+
ApiextensionsV1Api,
|
|
10
|
+
AdmissionregistrationV1Api,
|
|
11
|
+
)
|
|
12
|
+
from kubernetes.client.rest import ApiException
|
|
13
|
+
|
|
14
|
+
from jaseci.utils.utils import logger
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@JsOrc.service(name="kube", config="KUBE_CONFIG")
|
|
18
|
+
class KubeService(JsOrc.CommonService):
|
|
19
|
+
###################################################
|
|
20
|
+
# BUILDER #
|
|
21
|
+
###################################################
|
|
22
|
+
|
|
23
|
+
_no_namespace = [
|
|
24
|
+
"Namespace",
|
|
25
|
+
"ClusterRole",
|
|
26
|
+
"ClusterRoleBinding",
|
|
27
|
+
"CustomResourceDefinition",
|
|
28
|
+
"ValidatingWebhookConfiguration",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
def run(self):
|
|
32
|
+
self._in_cluster = self.config.get("in_cluster", True)
|
|
33
|
+
if self._in_cluster:
|
|
34
|
+
kubernetes_config.load_incluster_config()
|
|
35
|
+
else:
|
|
36
|
+
kubernetes_config.load_kube_config()
|
|
37
|
+
|
|
38
|
+
self.namespace = self.config.get("namespace", "default")
|
|
39
|
+
config = self.config.get("config")
|
|
40
|
+
|
|
41
|
+
self.app = ApiClient(config)
|
|
42
|
+
self.core = CoreV1Api(config)
|
|
43
|
+
self.api = AppsV1Api(self.app)
|
|
44
|
+
self.api_ext = ApiextensionsV1Api(self.app)
|
|
45
|
+
self.auth = RbacAuthorizationV1Api(self.app)
|
|
46
|
+
self.reg_api = AdmissionregistrationV1Api(self.app)
|
|
47
|
+
|
|
48
|
+
self.ping()
|
|
49
|
+
self.defaults()
|
|
50
|
+
|
|
51
|
+
def defaults(self):
|
|
52
|
+
self.create_apis = {
|
|
53
|
+
"Namespace": self.core.create_namespace,
|
|
54
|
+
"Service": self.core.create_namespaced_service,
|
|
55
|
+
"Deployment": self.api.create_namespaced_deployment,
|
|
56
|
+
"ConfigMap": self.core.create_namespaced_config_map,
|
|
57
|
+
"ServiceAccount": self.core.create_namespaced_service_account,
|
|
58
|
+
"ClusterRole": self.auth.create_cluster_role,
|
|
59
|
+
"ClusterRoleBinding": self.auth.create_cluster_role_binding,
|
|
60
|
+
"Secret": self.core.create_namespaced_secret,
|
|
61
|
+
"PersistentVolumeClaim": (
|
|
62
|
+
self.core.create_namespaced_persistent_volume_claim
|
|
63
|
+
),
|
|
64
|
+
"DaemonSet": self.api.create_namespaced_daemon_set,
|
|
65
|
+
"StatefulSet": self.api.create_namespaced_stateful_set,
|
|
66
|
+
"CustomResourceDefinition": self.api_ext.create_custom_resource_definition,
|
|
67
|
+
"ValidatingWebhookConfiguration": self.reg_api.create_validating_webhook_configuration,
|
|
68
|
+
}
|
|
69
|
+
self.patch_apis = {
|
|
70
|
+
"Namespace": self.core.patch_namespace,
|
|
71
|
+
"Service": self.core.patch_namespaced_service,
|
|
72
|
+
"Deployment": self.api.patch_namespaced_deployment,
|
|
73
|
+
"ConfigMap": self.core.patch_namespaced_config_map,
|
|
74
|
+
"ServiceAccount": self.core.patch_namespaced_service_account,
|
|
75
|
+
"ClusterRole": self.auth.patch_cluster_role,
|
|
76
|
+
"ClusterRoleBinding": self.auth.patch_cluster_role_binding,
|
|
77
|
+
"Secret": self.core.patch_namespaced_secret,
|
|
78
|
+
"PersistentVolumeClaim": (
|
|
79
|
+
self.core.patch_namespaced_persistent_volume_claim
|
|
80
|
+
),
|
|
81
|
+
"DaemonSet": self.api.patch_namespaced_daemon_set,
|
|
82
|
+
"StatefulSet": self.api.patch_namespaced_stateful_set,
|
|
83
|
+
"CustomResourceDefinition": self.api_ext.patch_custom_resource_definition,
|
|
84
|
+
"ValidatingWebhookConfiguration": self.reg_api.patch_validating_webhook_configuration,
|
|
85
|
+
}
|
|
86
|
+
self.delete_apis = {
|
|
87
|
+
"Namespace": self.core.delete_namespace,
|
|
88
|
+
"Service": self.core.delete_namespaced_service,
|
|
89
|
+
"Deployment": self.api.delete_namespaced_deployment,
|
|
90
|
+
"ConfigMap": self.core.delete_namespaced_config_map,
|
|
91
|
+
"ServiceAccount": self.core.delete_namespaced_service_account,
|
|
92
|
+
"ClusterRole": self.auth.delete_cluster_role,
|
|
93
|
+
"ClusterRoleBinding": self.auth.delete_cluster_role_binding,
|
|
94
|
+
"Secret": self.core.delete_namespaced_secret,
|
|
95
|
+
"PersistentVolumeClaim": (
|
|
96
|
+
self.core.delete_namespaced_persistent_volume_claim
|
|
97
|
+
),
|
|
98
|
+
"DaemonSet": self.api.delete_namespaced_daemon_set,
|
|
99
|
+
"StatefulSet": self.api.delete_namespaced_stateful_set,
|
|
100
|
+
"CustomResourceDefinition": self.api_ext.delete_custom_resource_definition,
|
|
101
|
+
"ValidatingWebhookConfiguration": self.reg_api.delete_validating_webhook_configuration,
|
|
102
|
+
}
|
|
103
|
+
self.read_apis = {
|
|
104
|
+
"Namespace": self.core.read_namespace,
|
|
105
|
+
"Service": self.core.read_namespaced_service,
|
|
106
|
+
"Endpoints": self.core.read_namespaced_endpoints,
|
|
107
|
+
"Deployment": self.api.read_namespaced_deployment,
|
|
108
|
+
"ConfigMap": self.core.read_namespaced_config_map,
|
|
109
|
+
"ServiceAccount": self.core.read_namespaced_service_account,
|
|
110
|
+
"ClusterRole": self.auth.read_cluster_role,
|
|
111
|
+
"ClusterRoleBinding": self.auth.read_cluster_role_binding,
|
|
112
|
+
"Secret": self.core.read_namespaced_secret,
|
|
113
|
+
"PersistentVolumeClaim": self.core.read_namespaced_persistent_volume_claim,
|
|
114
|
+
"DaemonSet": self.api.read_namespaced_daemon_set,
|
|
115
|
+
"StatefulSet": self.api.read_namespaced_stateful_set,
|
|
116
|
+
"CustomResourceDefinition": self.api_ext.read_custom_resource_definition,
|
|
117
|
+
"ValidatingWebhookConfiguration": self.reg_api.read_validating_webhook_configuration,
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
###################################################
|
|
121
|
+
# COMMONS #
|
|
122
|
+
###################################################
|
|
123
|
+
|
|
124
|
+
def ping(self):
|
|
125
|
+
res = self.app.call_api("/readyz", "GET")
|
|
126
|
+
return res[1] == 200
|
|
127
|
+
|
|
128
|
+
def in_cluster(self):
|
|
129
|
+
"""
|
|
130
|
+
Check if JSORC/Jaseci is running in a kubernetes cluster
|
|
131
|
+
"""
|
|
132
|
+
try:
|
|
133
|
+
return self._in_cluster and self.ping()
|
|
134
|
+
except ApiException as e:
|
|
135
|
+
logger.info(f"Kubernetes cluster environment check failed: {e}")
|
|
136
|
+
return False
|
|
137
|
+
|
|
138
|
+
def resolve_namespace(self, conf: dict, namespace: str = None):
|
|
139
|
+
return conf.get("metadata", {}).get("namespace") or namespace or self.namespace
|
|
140
|
+
|
|
141
|
+
def create(
|
|
142
|
+
self,
|
|
143
|
+
kind: str,
|
|
144
|
+
name: str,
|
|
145
|
+
conf: dict,
|
|
146
|
+
namespace: str = None,
|
|
147
|
+
log_pref: str = "",
|
|
148
|
+
):
|
|
149
|
+
namespace = self.resolve_namespace(conf, namespace)
|
|
150
|
+
try:
|
|
151
|
+
logger.info(
|
|
152
|
+
f"{log_pref} Creating {kind} for `{name}` with namespace `{namespace}`"
|
|
153
|
+
)
|
|
154
|
+
if kind in self._no_namespace:
|
|
155
|
+
self.create_apis[kind](body=conf)
|
|
156
|
+
else:
|
|
157
|
+
self.create_apis[kind](namespace=namespace, body=conf)
|
|
158
|
+
except ApiException as e:
|
|
159
|
+
logger.error(
|
|
160
|
+
f"{log_pref} Error creating {kind} for `{name}` with namespace `{namespace}` -- {e}"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
def patch(
|
|
164
|
+
self,
|
|
165
|
+
kind: str,
|
|
166
|
+
name: str,
|
|
167
|
+
conf: dict,
|
|
168
|
+
namespace: str = None,
|
|
169
|
+
log_pref: str = "",
|
|
170
|
+
):
|
|
171
|
+
namespace = self.resolve_namespace(conf, namespace)
|
|
172
|
+
try:
|
|
173
|
+
logger.info(
|
|
174
|
+
f"{log_pref} Patching {kind} for `{name}` with namespace `{namespace}`"
|
|
175
|
+
)
|
|
176
|
+
if kind in self._no_namespace:
|
|
177
|
+
self.patch_apis[kind](name=name, body=conf)
|
|
178
|
+
else:
|
|
179
|
+
self.patch_apis[kind](name=name, namespace=namespace, body=conf)
|
|
180
|
+
except ApiException as e:
|
|
181
|
+
logger.error(
|
|
182
|
+
f"{log_pref} Error patching {kind} for `{name}` with namespace `{namespace}` -- {e}"
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
def read(self, kind: str, name: str, namespace: str = None, log_pref: str = ""):
|
|
186
|
+
namespace = namespace or self.namespace
|
|
187
|
+
try:
|
|
188
|
+
logger.info(
|
|
189
|
+
f"{log_pref} Retrieving {kind} for `{name}` with namespace `{namespace}`"
|
|
190
|
+
)
|
|
191
|
+
if kind in self._no_namespace:
|
|
192
|
+
return self.read_apis[kind](name=name)
|
|
193
|
+
else:
|
|
194
|
+
return self.read_apis[kind](name=name, namespace=namespace)
|
|
195
|
+
except ApiException as e:
|
|
196
|
+
logger.error(
|
|
197
|
+
f"{log_pref} Error retrieving {kind} for `{name}` with namespace `{namespace}` -- {e}"
|
|
198
|
+
)
|
|
199
|
+
return e
|
|
200
|
+
|
|
201
|
+
def delete(self, kind: str, name: str, namespace: str = None, log_pref: str = ""):
|
|
202
|
+
namespace = namespace or self.namespace
|
|
203
|
+
try:
|
|
204
|
+
logger.info(
|
|
205
|
+
f"{log_pref} Deleting {kind} for `{name}` with namespace `{namespace}`"
|
|
206
|
+
)
|
|
207
|
+
if kind in self._no_namespace:
|
|
208
|
+
return self.delete_apis[kind](name=name)
|
|
209
|
+
else:
|
|
210
|
+
return self.delete_apis[kind](name=name, namespace=namespace)
|
|
211
|
+
except ApiException as e:
|
|
212
|
+
logger.error(
|
|
213
|
+
f"{log_pref} Error deleting {kind} for `{name}` with namespace `{namespace}` -- {e}"
|
|
214
|
+
)
|
|
215
|
+
return e
|
|
216
|
+
|
|
217
|
+
def is_pod_running(self, name: str, namespace: str = None):
|
|
218
|
+
namespace = namespace or self.namespace
|
|
219
|
+
try:
|
|
220
|
+
return (
|
|
221
|
+
self.core.list_namespaced_pod(
|
|
222
|
+
namespace=namespace, label_selector=f"pod={name}"
|
|
223
|
+
)
|
|
224
|
+
.items[0]
|
|
225
|
+
.status.phase
|
|
226
|
+
== "Running"
|
|
227
|
+
)
|
|
228
|
+
except Exception:
|
|
229
|
+
return False
|
|
230
|
+
|
|
231
|
+
def terminate_jaseci(self, name: str, namespace: str = None) -> bool:
|
|
232
|
+
namespace = namespace or self.namespace
|
|
233
|
+
try:
|
|
234
|
+
for item in self.core.list_namespaced_pod(
|
|
235
|
+
namespace=namespace, label_selector=f"pod={name}"
|
|
236
|
+
).items:
|
|
237
|
+
self.core.delete_namespaced_pod(item.metadata.name, namespace)
|
|
238
|
+
raise SystemExit("Force termination to restart the pod!")
|
|
239
|
+
except Exception:
|
|
240
|
+
return False
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import ssl
|
|
2
|
+
from json import dumps
|
|
2
3
|
from email.mime.multipart import MIMEMultipart
|
|
3
4
|
from email.mime.text import MIMEText
|
|
4
|
-
from json import dumps
|
|
5
5
|
from smtplib import SMTP, SMTP_SSL
|
|
6
6
|
|
|
7
|
-
from jaseci
|
|
8
|
-
from .config import MAIL_CONFIG
|
|
7
|
+
from jaseci import JsOrc
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
#################################################
|
|
12
|
-
#
|
|
11
|
+
# EMAIL APP #
|
|
13
12
|
#################################################
|
|
14
13
|
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
@JsOrc.service(name="mail", config="MAIL_CONFIG")
|
|
16
|
+
class MailService(JsOrc.CommonService):
|
|
17
17
|
###################################################
|
|
18
18
|
# BUILDER #
|
|
19
19
|
###################################################
|
|
20
20
|
|
|
21
|
-
def run(self
|
|
22
|
-
self.__convert_config(
|
|
21
|
+
def run(self):
|
|
22
|
+
self.__convert_config()
|
|
23
23
|
self.app = self.connect()
|
|
24
24
|
|
|
25
25
|
# ----------- BACKWARD COMPATIBILITY ------------ #
|
|
@@ -36,7 +36,8 @@ class MailService(CommonService):
|
|
|
36
36
|
holder[v] = conf
|
|
37
37
|
return holder
|
|
38
38
|
|
|
39
|
-
def __convert_config(self
|
|
39
|
+
def __convert_config(self):
|
|
40
|
+
hook = JsOrc.hook()
|
|
40
41
|
version = self.config.get("version", 2)
|
|
41
42
|
migrate = self.config.get("migrate", False)
|
|
42
43
|
if version == 1 or migrate:
|
|
@@ -78,12 +79,12 @@ class MailService(CommonService):
|
|
|
78
79
|
# CLEANER #
|
|
79
80
|
###################################################
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
# ---------------- PROXY EVENTS ----------------- #
|
|
83
|
+
|
|
84
|
+
def on_delete(self):
|
|
82
85
|
if self.is_running():
|
|
83
86
|
self.app.terminate()
|
|
84
87
|
|
|
85
|
-
super().reset(hook, start)
|
|
86
|
-
|
|
87
88
|
####################################################
|
|
88
89
|
# OVERRIDDEN #
|
|
89
90
|
####################################################
|
|
@@ -109,20 +110,16 @@ class MailService(CommonService):
|
|
|
109
110
|
|
|
110
111
|
return Mailer(server, sender)
|
|
111
112
|
|
|
112
|
-
def build_config(self, hook) -> dict:
|
|
113
|
-
return hook.service_glob("MAIL_CONFIG", MAIL_CONFIG)
|
|
114
|
-
|
|
115
113
|
|
|
116
114
|
# ----------------------------------------------- #
|
|
117
115
|
|
|
118
|
-
|
|
119
116
|
####################################################
|
|
120
|
-
#
|
|
117
|
+
# MAILER #
|
|
121
118
|
####################################################
|
|
122
119
|
|
|
123
120
|
|
|
124
121
|
class Mailer:
|
|
125
|
-
def __init__(self, server, sender):
|
|
122
|
+
def __init__(self, server: SMTP, sender):
|
|
126
123
|
self.server = server
|
|
127
124
|
self.sender = sender
|
|
128
125
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
from prometheus_api_client import PrometheusConnect
|
|
2
|
-
from jaseci.svc import CommonService
|
|
3
|
-
from .config import PROMON_CONFIG
|
|
4
|
-
from .manifest import PROMON_MANIFEST
|
|
5
1
|
import time
|
|
2
|
+
from prometheus_api_client import PrometheusConnect
|
|
3
|
+
from jaseci import JsOrc
|
|
6
4
|
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
@JsOrc.service(name="prome", config="PROME_CONFIG", manifest="PROME_MANIFEST")
|
|
7
|
+
class PrometheusService(JsOrc.CommonService):
|
|
9
8
|
###################################################
|
|
10
9
|
# BUILDER #
|
|
11
10
|
###################################################
|
|
12
11
|
|
|
13
|
-
def run(self
|
|
12
|
+
def run(self):
|
|
14
13
|
self.app = PrometheusConnect(url=self.config.get("url"), disable_ssl=True)
|
|
15
14
|
self.ping()
|
|
16
15
|
self.cpu = Cpu(self.app)
|
|
@@ -117,16 +116,6 @@ class PrometheusService(CommonService):
|
|
|
117
116
|
|
|
118
117
|
return res
|
|
119
118
|
|
|
120
|
-
####################################################
|
|
121
|
-
# OVERRIDDEN #
|
|
122
|
-
####################################################
|
|
123
|
-
|
|
124
|
-
def build_config(self, hook) -> dict:
|
|
125
|
-
return hook.service_glob("PROMON_CONFIG", PROMON_CONFIG)
|
|
126
|
-
|
|
127
|
-
def build_manifest(self, hook) -> dict:
|
|
128
|
-
return hook.service_glob("PROMON_MANIFEST", PROMON_MANIFEST)
|
|
129
|
-
|
|
130
119
|
|
|
131
120
|
class Info:
|
|
132
121
|
def __init__(self, app):
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
+
from jaseci import JsOrc
|
|
1
2
|
from redis import Redis
|
|
2
3
|
|
|
3
|
-
from jaseci.svc import CommonService
|
|
4
|
-
from .config import REDIS_CONFIG
|
|
5
|
-
from .manifest import REDIS_MANIFEST
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
###################################################
|
|
17
|
-
|
|
18
|
-
def run(self, hook=None):
|
|
5
|
+
@JsOrc.service(
|
|
6
|
+
name="redis",
|
|
7
|
+
config="REDIS_CONFIG",
|
|
8
|
+
manifest="REDIS_MANIFEST",
|
|
9
|
+
priority=0,
|
|
10
|
+
proxy=True,
|
|
11
|
+
)
|
|
12
|
+
class RedisService(JsOrc.CommonService):
|
|
13
|
+
def run(self):
|
|
19
14
|
self.app = Redis(**self.config, decode_responses=True)
|
|
20
15
|
self.app.ping()
|
|
21
16
|
|
|
@@ -58,15 +53,8 @@ class RedisService(CommonService):
|
|
|
58
53
|
if self.is_running():
|
|
59
54
|
self.app.flushdb()
|
|
60
55
|
|
|
61
|
-
|
|
62
|
-
# CONFIG #
|
|
63
|
-
###################################################
|
|
64
|
-
|
|
65
|
-
def build_config(self, hook) -> dict:
|
|
66
|
-
return hook.service_glob("REDIS_CONFIG", REDIS_CONFIG)
|
|
56
|
+
# ---------------- PROXY EVENTS ----------------- #
|
|
67
57
|
|
|
68
|
-
def
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# ----------------------------------------------- #
|
|
58
|
+
def on_delete(self):
|
|
59
|
+
if self.is_running():
|
|
60
|
+
self.app.close()
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import stripe
|
|
2
|
-
from jaseci
|
|
3
|
-
from .config import STRIPE_CONFIG
|
|
2
|
+
from jaseci import JsOrc
|
|
4
3
|
|
|
5
4
|
#################################################
|
|
6
5
|
# STRIPE APP #
|
|
7
6
|
#################################################
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
@JsOrc.service("stripe", config="STRIPE_CONFIG")
|
|
10
|
+
class StripeService(JsOrc.CommonService):
|
|
11
11
|
###################################################
|
|
12
12
|
# BUILDER #
|
|
13
13
|
###################################################
|
|
14
14
|
|
|
15
|
-
def run(self
|
|
15
|
+
def run(self):
|
|
16
16
|
self.app = stripe
|
|
17
17
|
if not self.config.get("api_key"):
|
|
18
18
|
raise Exception("api_key is required!")
|
|
@@ -49,6 +49,3 @@ class StripeService(CommonService):
|
|
|
49
49
|
def reset(self, hook, start=True):
|
|
50
50
|
stripe.api_key = None
|
|
51
51
|
super().reset(hook, start)
|
|
52
|
-
|
|
53
|
-
def build_config(self, hook) -> dict:
|
|
54
|
-
return hook.service_glob("STRIPE_CONFIG", STRIPE_CONFIG)
|
|
@@ -1,54 +1,64 @@
|
|
|
1
1
|
from celery import Celery
|
|
2
|
+
from celery.app.trace import build_tracer
|
|
2
3
|
from celery.app.control import Inspect
|
|
3
4
|
from celery.backends.base import DisabledBackend
|
|
4
5
|
|
|
5
|
-
from jaseci
|
|
6
|
-
from .
|
|
7
|
-
from .config import TASK_CONFIG
|
|
6
|
+
from jaseci import JsOrc
|
|
7
|
+
from .tasks import Queue, ScheduledWalker, ScheduledSequence
|
|
8
8
|
|
|
9
9
|
#################################################
|
|
10
10
|
# TASK APP #
|
|
11
11
|
#################################################
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
@JsOrc.service(name="task", config="TASK_CONFIG")
|
|
15
|
+
class TaskService(JsOrc.CommonService):
|
|
15
16
|
###################################################
|
|
16
17
|
# INITIALIZER #
|
|
17
18
|
###################################################
|
|
18
19
|
|
|
19
|
-
def __init__(self,
|
|
20
|
+
def __init__(self, config: dict, manifest: dict):
|
|
20
21
|
self.inspect: Inspect = None
|
|
21
22
|
self.queue: Queue = None
|
|
22
23
|
self.scheduled_walker: ScheduledWalker = None
|
|
23
24
|
self.scheduled_sequence: ScheduledSequence = None
|
|
24
25
|
|
|
25
|
-
super().__init__(
|
|
26
|
+
super().__init__(config, manifest)
|
|
26
27
|
|
|
27
28
|
###################################################
|
|
28
29
|
# BUILDER #
|
|
29
30
|
###################################################
|
|
30
31
|
|
|
31
|
-
def run(self
|
|
32
|
+
def run(self):
|
|
32
33
|
self.app = Celery("celery")
|
|
33
34
|
self.app.conf.update(**self.config)
|
|
34
35
|
|
|
35
36
|
# -------------------- TASKS -------------------- #
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
(
|
|
38
|
+
self.queue,
|
|
39
|
+
self.scheduled_walker,
|
|
40
|
+
self.scheduled_sequence,
|
|
41
|
+
) = self.register_tasks(Queue, ScheduledWalker, ScheduledSequence)
|
|
40
42
|
|
|
41
43
|
# ------------------ INSPECTOR ------------------ #
|
|
42
44
|
|
|
43
45
|
self.inspect = self.app.control.inspect()
|
|
44
46
|
self.ping()
|
|
45
47
|
|
|
46
|
-
def post_run(self
|
|
48
|
+
def post_run(self):
|
|
47
49
|
self.spawn_daemon(
|
|
48
50
|
worker=self.app.Worker(quiet=self.quiet).start,
|
|
49
51
|
scheduler=self.app.Beat(socket_timeout=None, quiet=self.quiet).run,
|
|
50
52
|
)
|
|
51
53
|
|
|
54
|
+
def register_tasks(self, *tasks) -> tuple:
|
|
55
|
+
registered = []
|
|
56
|
+
for task in tasks:
|
|
57
|
+
task = self.app.register_task(task())
|
|
58
|
+
task.__trace__ = build_tracer(task.name, task, app=self.app)
|
|
59
|
+
registered.append(task)
|
|
60
|
+
return tuple(registered)
|
|
61
|
+
|
|
52
62
|
###################################################
|
|
53
63
|
# COMMON GETTER/SETTER #
|
|
54
64
|
###################################################
|
|
@@ -93,18 +103,11 @@ class TaskService(CommonService):
|
|
|
93
103
|
# CLEANER #
|
|
94
104
|
###################################################
|
|
95
105
|
|
|
96
|
-
def
|
|
106
|
+
def failed(self, error):
|
|
107
|
+
super().failed(error)
|
|
97
108
|
self.terminate_daemon("worker", "scheduler")
|
|
98
|
-
self.inspect = None
|
|
99
|
-
super().reset(hook, start)
|
|
100
109
|
|
|
101
|
-
|
|
102
|
-
super().failed()
|
|
103
|
-
self.terminate_daemon("worker", "scheduler")
|
|
110
|
+
# ---------------- PROXY EVENTS ----------------- #
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
####################################################
|
|
108
|
-
|
|
109
|
-
def build_config(self, hook) -> dict:
|
|
110
|
-
return hook.service_glob("TASK_CONFIG", TASK_CONFIG)
|
|
112
|
+
def on_delete(self):
|
|
113
|
+
self.terminate_daemon("worker", "scheduler")
|