elody 0.0.220__tar.gz → 0.0.222__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {elody-0.0.220 → elody-0.0.222}/PKG-INFO +1 -1
- {elody-0.0.220 → elody-0.0.222}/pyproject.toml +1 -1
- elody-0.0.222/src/elody/job.py +86 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/object_configurations/base_object_configuration.py +11 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/object_configurations/elody_configuration.py +3 -0
- elody-0.0.222/src/elody/object_configurations/job_configuration.py +245 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/util.py +13 -2
- {elody-0.0.220 → elody-0.0.222}/src/elody.egg-info/PKG-INFO +1 -1
- elody-0.0.220/src/elody/job.py +0 -110
- elody-0.0.220/src/elody/object_configurations/job_configuration.py +0 -51
- {elody-0.0.220 → elody-0.0.222}/LICENSE +0 -0
- {elody-0.0.220 → elody-0.0.222}/README.md +0 -0
- {elody-0.0.220 → elody-0.0.222}/setup.cfg +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/__init__.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/__init__.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/client.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/csv.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/error_codes.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/exceptions.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/loader.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/migration/__init__.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/migration/base_object_migrator.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/object_configurations/__init__.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/object_configurations/saved_search_configuration.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/__init__.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authentication/__init__.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authentication/base_user_tenant_validation_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authentication/multi_tenant_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/__init__.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/filter_generic_objects_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/filter_generic_objects_policy_v2.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_detail_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_mediafiles_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_metadata_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_relations_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_request_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_request_policy_v2.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/mediafile_derivatives_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/mediafile_download_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/multi_tenant_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/tenant_request_policy.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/helpers.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/policies/permission_handler.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/schemas.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody/validator.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody.egg-info/SOURCES.txt +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody.egg-info/dependency_links.txt +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody.egg-info/requires.txt +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/elody.egg-info/top_level.txt +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/tests/__init_.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/tests/data.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/tests/unit/__init__.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/tests/unit/test_csv.py +0 -0
- {elody-0.0.220 → elody-0.0.222}/src/tests/unit/test_utils.py +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from config import get_object_configuration_mapper
|
|
3
|
+
|
|
4
|
+
_config = get_object_configuration_mapper().get("job")
|
|
5
|
+
except ModuleNotFoundError:
|
|
6
|
+
from elody.object_configurations.job_configuration import JobConfiguration
|
|
7
|
+
|
|
8
|
+
_config = JobConfiguration()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def add_document_to_job(
|
|
12
|
+
id,
|
|
13
|
+
id_of_document_job_was_initiated_for,
|
|
14
|
+
*,
|
|
15
|
+
get_rabbit,
|
|
16
|
+
):
|
|
17
|
+
_config.crud()["add_document_to_job"](
|
|
18
|
+
id=id,
|
|
19
|
+
id_of_document_job_was_initiated_for=id_of_document_job_was_initiated_for,
|
|
20
|
+
get_rabbit=get_rabbit,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def init_job(
|
|
25
|
+
name,
|
|
26
|
+
job_type,
|
|
27
|
+
*,
|
|
28
|
+
get_rabbit,
|
|
29
|
+
get_user_context=None,
|
|
30
|
+
user_email=None,
|
|
31
|
+
parent_id=None,
|
|
32
|
+
id_of_document_job_was_initiated_for=None,
|
|
33
|
+
track_async_children: bool | None = None,
|
|
34
|
+
) -> str:
|
|
35
|
+
return _config.crud()["init_job"](
|
|
36
|
+
name=name,
|
|
37
|
+
job_type=job_type,
|
|
38
|
+
get_rabbit=get_rabbit,
|
|
39
|
+
get_user_context=get_user_context,
|
|
40
|
+
user_email=user_email,
|
|
41
|
+
parent_id=parent_id,
|
|
42
|
+
id_of_document_job_was_initiated_for=id_of_document_job_was_initiated_for,
|
|
43
|
+
track_async_children=track_async_children,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def start_job(
|
|
48
|
+
id,
|
|
49
|
+
*,
|
|
50
|
+
get_rabbit,
|
|
51
|
+
):
|
|
52
|
+
_config.crud()["start_job"](
|
|
53
|
+
id=id,
|
|
54
|
+
get_rabbit=get_rabbit,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def finish_job(
|
|
59
|
+
id,
|
|
60
|
+
*,
|
|
61
|
+
get_rabbit,
|
|
62
|
+
):
|
|
63
|
+
_config.crud()["finish_job"](
|
|
64
|
+
id=id,
|
|
65
|
+
get_rabbit=get_rabbit,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def soft_finish_job(
|
|
70
|
+
id,
|
|
71
|
+
*,
|
|
72
|
+
get_rabbit,
|
|
73
|
+
):
|
|
74
|
+
_config.crud()["soft_finish_job"](id=id, get_rabbit=get_rabbit)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def fail_job(id, exception_message, *, get_rabbit):
|
|
78
|
+
_config.crud()["fail_job"](
|
|
79
|
+
id=id, exception_message=exception_message, get_rabbit=get_rabbit
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def handle_parent_job_finished(id, parent_child_status, *, get_rabbit):
|
|
84
|
+
_config.crud()["handle_parent_job_finished"](
|
|
85
|
+
id=id, parent_child_status=parent_child_status, get_rabbit=get_rabbit
|
|
86
|
+
)
|
{elody-0.0.220 → elody-0.0.222}/src/elody/object_configurations/base_object_configuration.py
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from copy import deepcopy
|
|
3
3
|
from elody.migration.base_object_migrator import BaseObjectMigrator
|
|
4
|
+
from os import getenv
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
class BaseObjectConfiguration(ABC):
|
|
@@ -95,6 +96,16 @@ class BaseObjectConfiguration(ABC):
|
|
|
95
96
|
except Exception:
|
|
96
97
|
return None
|
|
97
98
|
|
|
99
|
+
def _is_request_from_internal_service(self):
|
|
100
|
+
try:
|
|
101
|
+
from flask import request # pyright: ignore
|
|
102
|
+
|
|
103
|
+
return request.headers.get("Authorization", "").removeprefix(
|
|
104
|
+
"Bearer "
|
|
105
|
+
) == getenv("STATIC_JWT")
|
|
106
|
+
except Exception:
|
|
107
|
+
return False
|
|
108
|
+
|
|
98
109
|
def _sanitize_document(self, *, document, **kwargs):
|
|
99
110
|
sanitized_document = {}
|
|
100
111
|
document_deepcopy = deepcopy(document)
|
|
@@ -177,6 +177,9 @@ class ElodyConfiguration(BaseObjectConfiguration):
|
|
|
177
177
|
return sanitized_document
|
|
178
178
|
|
|
179
179
|
def __patch_document_audit_info(self, crud, document, timestamp, audit_override):
|
|
180
|
+
if self._is_request_from_internal_service():
|
|
181
|
+
return document
|
|
182
|
+
|
|
180
183
|
document.update({f"date_{crud}d": timestamp})
|
|
181
184
|
if email := self._get_user_context_id():
|
|
182
185
|
label = f"{crud}d_by" if crud == "create" else "last_editor"
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
from datetime import datetime, timezone
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from os import getenv
|
|
4
|
+
from typing import Literal
|
|
5
|
+
|
|
6
|
+
from elody.object_configurations.elody_configuration import (
|
|
7
|
+
ElodyConfiguration,
|
|
8
|
+
)
|
|
9
|
+
from elody.util import send_cloudevent
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Status(str, Enum):
|
|
13
|
+
QUEUED = "queued"
|
|
14
|
+
RUNNING = "running"
|
|
15
|
+
FINISHED = "finished"
|
|
16
|
+
FAILED = "failed"
|
|
17
|
+
WARNING = "warning"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class JobConfiguration(ElodyConfiguration):
|
|
21
|
+
SCHEMA_TYPE = "elody"
|
|
22
|
+
SCHEMA_VERSION = 1
|
|
23
|
+
|
|
24
|
+
def crud(self):
|
|
25
|
+
crud = {
|
|
26
|
+
"collection": "jobs",
|
|
27
|
+
"collection_history": "",
|
|
28
|
+
"add_document_to_job": lambda *args, **kwargs: self._add_document_to_job(
|
|
29
|
+
*args, **kwargs
|
|
30
|
+
),
|
|
31
|
+
"init_job": lambda *args, **kwargs: self._init_job(*args, **kwargs),
|
|
32
|
+
"start_job": lambda *args, **kwargs: self._start_job(*args, **kwargs),
|
|
33
|
+
"finish_job": lambda *args, **kwargs: self._finish_job(*args, **kwargs),
|
|
34
|
+
"finish_job_with_warning": lambda *args, **kwargs: self._finish_job_with_warning(
|
|
35
|
+
*args, **kwargs
|
|
36
|
+
),
|
|
37
|
+
"fail_job": lambda *args, **kwargs: self._fail_job(*args, **kwargs),
|
|
38
|
+
"handle_parent_job_finished": lambda *args, **kwargs: self._handle_parent_job_finished(
|
|
39
|
+
*args, **kwargs
|
|
40
|
+
),
|
|
41
|
+
}
|
|
42
|
+
return {**super().crud(), **crud}
|
|
43
|
+
|
|
44
|
+
def document_info(self):
|
|
45
|
+
return super().document_info()
|
|
46
|
+
|
|
47
|
+
def logging(self, flat_document, **kwargs):
|
|
48
|
+
return super().logging(flat_document, **kwargs)
|
|
49
|
+
|
|
50
|
+
def migration(self):
|
|
51
|
+
return super().migration()
|
|
52
|
+
|
|
53
|
+
def serialization(self, from_format, to_format):
|
|
54
|
+
return super().serialization(from_format, to_format)
|
|
55
|
+
|
|
56
|
+
def validation(self):
|
|
57
|
+
return super().validation()
|
|
58
|
+
|
|
59
|
+
def _creator(self, post_body, *, get_user_context={}, **_):
|
|
60
|
+
document = super()._creator(post_body)
|
|
61
|
+
if email := get_user_context().email:
|
|
62
|
+
document["last_editor"] = email
|
|
63
|
+
return document
|
|
64
|
+
|
|
65
|
+
def _post_crud_hook(self, *, crud, document, get_rabbit, **kwargs):
|
|
66
|
+
if crud == "create":
|
|
67
|
+
send_cloudevent(
|
|
68
|
+
get_rabbit(),
|
|
69
|
+
getenv("MQ_EXCHANGE", "dams"),
|
|
70
|
+
"dams.job_created",
|
|
71
|
+
document,
|
|
72
|
+
)
|
|
73
|
+
elif crud == "update":
|
|
74
|
+
send_cloudevent(
|
|
75
|
+
get_rabbit(),
|
|
76
|
+
getenv("MQ_EXCHANGE", "dams"),
|
|
77
|
+
"dams.job_changed",
|
|
78
|
+
document,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
def _add_document_to_job(
|
|
82
|
+
self,
|
|
83
|
+
id,
|
|
84
|
+
id_of_document_job_was_initiated_for,
|
|
85
|
+
*,
|
|
86
|
+
get_rabbit,
|
|
87
|
+
):
|
|
88
|
+
relations = []
|
|
89
|
+
if id_of_document_job_was_initiated_for:
|
|
90
|
+
relations.append(
|
|
91
|
+
{"key": id_of_document_job_was_initiated_for, "type": "isJobFor"}
|
|
92
|
+
)
|
|
93
|
+
document = {
|
|
94
|
+
"id": id,
|
|
95
|
+
"patch": {
|
|
96
|
+
"relations": (relations),
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
self._post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
100
|
+
|
|
101
|
+
def _init_job(
|
|
102
|
+
self,
|
|
103
|
+
name,
|
|
104
|
+
job_type,
|
|
105
|
+
*,
|
|
106
|
+
get_rabbit,
|
|
107
|
+
get_user_context=None,
|
|
108
|
+
user_email=None,
|
|
109
|
+
parent_id=None,
|
|
110
|
+
id_of_document_job_was_initiated_for=None,
|
|
111
|
+
track_async_children: bool | None = None,
|
|
112
|
+
) -> str:
|
|
113
|
+
relations = []
|
|
114
|
+
if parent_id:
|
|
115
|
+
relations.append({"key": parent_id, "type": "hasParentJob"})
|
|
116
|
+
if id_of_document_job_was_initiated_for:
|
|
117
|
+
relations.append(
|
|
118
|
+
{"key": id_of_document_job_was_initiated_for, "type": "isJobFor"}
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
metadata = [
|
|
122
|
+
{"key": "name", "value": name},
|
|
123
|
+
{"key": "status", "value": Status.QUEUED.value},
|
|
124
|
+
{"key": "type", "value": job_type},
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
if track_async_children:
|
|
128
|
+
metadata.append(
|
|
129
|
+
{
|
|
130
|
+
"key": "child_jobs",
|
|
131
|
+
"value": {
|
|
132
|
+
Status.QUEUED.value: 0,
|
|
133
|
+
Status.RUNNING.value: 0,
|
|
134
|
+
Status.FAILED.value: 0,
|
|
135
|
+
Status.FINISHED.value: 0,
|
|
136
|
+
Status.WARNING.value: 0,
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
job = self.crud()["creator"](
|
|
142
|
+
{
|
|
143
|
+
"metadata": metadata,
|
|
144
|
+
"relations": relations,
|
|
145
|
+
"type": "job",
|
|
146
|
+
},
|
|
147
|
+
get_user_context=get_user_context
|
|
148
|
+
or (lambda: type("UserContext", (object,), {"email": user_email})()),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
self._post_crud_hook(
|
|
152
|
+
crud="create", document=job, parent_id=parent_id, get_rabbit=get_rabbit
|
|
153
|
+
)
|
|
154
|
+
return job["_id"]
|
|
155
|
+
|
|
156
|
+
def _start_job(
|
|
157
|
+
self,
|
|
158
|
+
id,
|
|
159
|
+
*,
|
|
160
|
+
get_rabbit,
|
|
161
|
+
):
|
|
162
|
+
document = {
|
|
163
|
+
"id": id,
|
|
164
|
+
"patch": {
|
|
165
|
+
"started_at": datetime.now(timezone.utc),
|
|
166
|
+
"metadata": [{"key": "status", "value": Status.RUNNING.value}],
|
|
167
|
+
},
|
|
168
|
+
}
|
|
169
|
+
self._post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
170
|
+
|
|
171
|
+
def _finish_job(
|
|
172
|
+
self,
|
|
173
|
+
id,
|
|
174
|
+
*,
|
|
175
|
+
get_rabbit,
|
|
176
|
+
):
|
|
177
|
+
document = {
|
|
178
|
+
"id": id,
|
|
179
|
+
"patch": {
|
|
180
|
+
"metadata": [{"key": "status", "value": Status.FINISHED.value}],
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
self._post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
184
|
+
|
|
185
|
+
def _finish_job_with_warning(
|
|
186
|
+
self,
|
|
187
|
+
id,
|
|
188
|
+
*,
|
|
189
|
+
get_rabbit,
|
|
190
|
+
info_message=None,
|
|
191
|
+
):
|
|
192
|
+
document = {
|
|
193
|
+
"id": id,
|
|
194
|
+
"patch": {
|
|
195
|
+
"metadata": [
|
|
196
|
+
{"key": "status", "value": Status.FINISHED.value},
|
|
197
|
+
{"key": "info", "value": info_message},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
self._post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
202
|
+
|
|
203
|
+
def _fail_job(self, id, exception_message, *, get_rabbit):
|
|
204
|
+
|
|
205
|
+
status, message = self.__handle_error_warnings(exception_message)
|
|
206
|
+
|
|
207
|
+
document = {
|
|
208
|
+
"id": id,
|
|
209
|
+
"patch": {
|
|
210
|
+
"metadata": [
|
|
211
|
+
{"key": "info", "value": message},
|
|
212
|
+
{
|
|
213
|
+
"key": "status",
|
|
214
|
+
"value": (status.value),
|
|
215
|
+
},
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
self._post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
220
|
+
|
|
221
|
+
def _handle_parent_job_finished(self, id, parent_child_status, *, get_rabbit):
|
|
222
|
+
|
|
223
|
+
child_jobs_failed = parent_child_status[Status.FAILED.value]
|
|
224
|
+
child_jobs_warning = parent_child_status[Status.WARNING.value]
|
|
225
|
+
|
|
226
|
+
if child_jobs_failed == 0:
|
|
227
|
+
if child_jobs_warning:
|
|
228
|
+
self.crud()["finish_job_with_warning"](
|
|
229
|
+
id, get_rabbit=get_rabbit, info_message="Some subjobs have warnings"
|
|
230
|
+
)
|
|
231
|
+
self.crud()["finish_job"](id, get_rabbit=get_rabbit)
|
|
232
|
+
else:
|
|
233
|
+
self.crud()["fail_job"](
|
|
234
|
+
id, exception_message="some subjobs failed", get_rabbit=get_rabbit
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
def __handle_error_warnings(
|
|
238
|
+
self,
|
|
239
|
+
errormessage: str,
|
|
240
|
+
) -> tuple[Literal[Status.WARNING] | Literal[Status.FAILED], str]:
|
|
241
|
+
|
|
242
|
+
if errormessage.startswith("W4009"):
|
|
243
|
+
return Status.WARNING, errormessage
|
|
244
|
+
|
|
245
|
+
return Status.FAILED, errormessage
|
|
@@ -125,6 +125,13 @@ def get_item_metadata_value(item, key):
|
|
|
125
125
|
return ""
|
|
126
126
|
|
|
127
127
|
|
|
128
|
+
def get_item_relation_key(item, type):
|
|
129
|
+
for item in item.get("relations", []):
|
|
130
|
+
if item["type"] == type:
|
|
131
|
+
return item["key"]
|
|
132
|
+
return ""
|
|
133
|
+
|
|
134
|
+
|
|
128
135
|
def get_mimetype_from_filename(filename):
|
|
129
136
|
mime = mimetypes.guess_type(filename, False)[0]
|
|
130
137
|
return mime if mime else "application/octet-stream"
|
|
@@ -267,8 +274,12 @@ def signal_update_copyright_color_mediafile(mq_client, mediafile_id):
|
|
|
267
274
|
send_cloudevent(mq_client, "dams", "dams.update_copyright_color_mediafile", data)
|
|
268
275
|
|
|
269
276
|
|
|
270
|
-
def signal_upload_file(mq_client, upload_links, selected_folder):
|
|
271
|
-
data = {
|
|
277
|
+
def signal_upload_file(mq_client, upload_links, selected_folder, parent_job_id=None):
|
|
278
|
+
data = {
|
|
279
|
+
"upload_links": upload_links,
|
|
280
|
+
"selected_folder": selected_folder,
|
|
281
|
+
"parent_job_id": parent_job_id,
|
|
282
|
+
}
|
|
272
283
|
send_cloudevent(mq_client, "dams", "dams.upload_file", data)
|
|
273
284
|
|
|
274
285
|
|
elody-0.0.220/src/elody/job.py
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
from elody.object_configurations.job_configuration import JobConfiguration
|
|
2
|
-
from datetime import datetime, timezone
|
|
3
|
-
|
|
4
|
-
_config = JobConfiguration()
|
|
5
|
-
_create = _config.crud()["creator"]
|
|
6
|
-
_post_crud_hook = _config.crud()["post_crud_hook"]
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def add_document_to_job(
|
|
10
|
-
id,
|
|
11
|
-
id_of_document_job_was_initiated_for,
|
|
12
|
-
*,
|
|
13
|
-
get_rabbit,
|
|
14
|
-
):
|
|
15
|
-
relations = []
|
|
16
|
-
if id_of_document_job_was_initiated_for:
|
|
17
|
-
relations.append(
|
|
18
|
-
{"key": id_of_document_job_was_initiated_for, "type": "isJobFor"}
|
|
19
|
-
)
|
|
20
|
-
document = {
|
|
21
|
-
"id": id,
|
|
22
|
-
"patch": {
|
|
23
|
-
"relations": (relations),
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
_post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def init_job(
|
|
30
|
-
name,
|
|
31
|
-
job_type,
|
|
32
|
-
*,
|
|
33
|
-
get_rabbit,
|
|
34
|
-
get_user_context=None,
|
|
35
|
-
user_email=None,
|
|
36
|
-
parent_id=None,
|
|
37
|
-
id_of_document_job_was_initiated_for=None,
|
|
38
|
-
) -> str:
|
|
39
|
-
relations = []
|
|
40
|
-
if parent_id:
|
|
41
|
-
relations.append({"key": parent_id, "type": "hasParentJob"})
|
|
42
|
-
if id_of_document_job_was_initiated_for:
|
|
43
|
-
relations.append(
|
|
44
|
-
{"key": id_of_document_job_was_initiated_for, "type": "isJobFor"}
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
job = _create(
|
|
48
|
-
{
|
|
49
|
-
"metadata": [
|
|
50
|
-
{"key": "name", "value": name},
|
|
51
|
-
{"key": "status", "value": "queued"},
|
|
52
|
-
{"key": "type", "value": job_type},
|
|
53
|
-
],
|
|
54
|
-
"relations": relations,
|
|
55
|
-
"type": "job",
|
|
56
|
-
},
|
|
57
|
-
get_user_context=get_user_context
|
|
58
|
-
or (lambda: type("UserContext", (object,), {"email": user_email})()),
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
_post_crud_hook(
|
|
62
|
-
crud="create", document=job, parent_id=parent_id, get_rabbit=get_rabbit
|
|
63
|
-
)
|
|
64
|
-
return job["_id"]
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def start_job(
|
|
68
|
-
id,
|
|
69
|
-
id_of_document_job_was_initiated_for=None,
|
|
70
|
-
*,
|
|
71
|
-
get_rabbit,
|
|
72
|
-
):
|
|
73
|
-
document = {
|
|
74
|
-
"id": id,
|
|
75
|
-
"patch": {
|
|
76
|
-
"started_at": datetime.now(timezone.utc),
|
|
77
|
-
"metadata": [{"key": "status", "value": "running"}],
|
|
78
|
-
"relations": ([] if id_of_document_job_was_initiated_for else []),
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
-
_post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def finish_job(
|
|
85
|
-
id,
|
|
86
|
-
id_of_document_job_was_initiated_for=None,
|
|
87
|
-
*,
|
|
88
|
-
get_rabbit,
|
|
89
|
-
):
|
|
90
|
-
document = {
|
|
91
|
-
"id": id,
|
|
92
|
-
"patch": {
|
|
93
|
-
"metadata": [{"key": "status", "value": "finished"}],
|
|
94
|
-
"relations": ([] if id_of_document_job_was_initiated_for else []),
|
|
95
|
-
},
|
|
96
|
-
}
|
|
97
|
-
_post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def fail_job(id, exception_message, *, get_rabbit):
|
|
101
|
-
document = {
|
|
102
|
-
"id": id,
|
|
103
|
-
"patch": {
|
|
104
|
-
"metadata": [
|
|
105
|
-
{"key": "info", "value": exception_message},
|
|
106
|
-
{"key": "status", "value": "failed"},
|
|
107
|
-
]
|
|
108
|
-
},
|
|
109
|
-
}
|
|
110
|
-
_post_crud_hook(crud="update", document=document, get_rabbit=get_rabbit)
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
from elody.object_configurations.elody_configuration import (
|
|
2
|
-
ElodyConfiguration,
|
|
3
|
-
)
|
|
4
|
-
from elody.util import send_cloudevent
|
|
5
|
-
from os import getenv
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class JobConfiguration(ElodyConfiguration):
|
|
9
|
-
SCHEMA_TYPE = "elody"
|
|
10
|
-
SCHEMA_VERSION = 1
|
|
11
|
-
|
|
12
|
-
def crud(self):
|
|
13
|
-
crud = {"collection": "jobs", "collection_history": ""}
|
|
14
|
-
return {**super().crud(), **crud}
|
|
15
|
-
|
|
16
|
-
def document_info(self):
|
|
17
|
-
return super().document_info()
|
|
18
|
-
|
|
19
|
-
def logging(self, flat_document, **kwargs):
|
|
20
|
-
return super().logging(flat_document, **kwargs)
|
|
21
|
-
|
|
22
|
-
def migration(self):
|
|
23
|
-
return super().migration()
|
|
24
|
-
|
|
25
|
-
def serialization(self, from_format, to_format):
|
|
26
|
-
return super().serialization(from_format, to_format)
|
|
27
|
-
|
|
28
|
-
def validation(self):
|
|
29
|
-
return super().validation()
|
|
30
|
-
|
|
31
|
-
def _creator(self, post_body, *, get_user_context={}, **_):
|
|
32
|
-
document = super()._creator(post_body)
|
|
33
|
-
if email := get_user_context().email:
|
|
34
|
-
document["last_editor"] = email
|
|
35
|
-
return document
|
|
36
|
-
|
|
37
|
-
def _post_crud_hook(self, *, crud, document, get_rabbit, **kwargs):
|
|
38
|
-
if crud == "create":
|
|
39
|
-
send_cloudevent(
|
|
40
|
-
get_rabbit(),
|
|
41
|
-
getenv("MQ_EXCHANGE", "dams"),
|
|
42
|
-
"dams.job_created",
|
|
43
|
-
document,
|
|
44
|
-
)
|
|
45
|
-
elif crud == "update":
|
|
46
|
-
send_cloudevent(
|
|
47
|
-
get_rabbit(),
|
|
48
|
-
getenv("MQ_EXCHANGE", "dams"),
|
|
49
|
-
"dams.job_changed",
|
|
50
|
-
document,
|
|
51
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/object_configurations/saved_search_configuration.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/filter_generic_objects_policy.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/filter_generic_objects_policy_v2.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_detail_policy.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_mediafiles_policy.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_metadata_policy.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_relations_policy.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_request_policy.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/generic_object_request_policy_v2.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/mediafile_derivatives_policy.py
RENAMED
|
File without changes
|
{elody-0.0.220 → elody-0.0.222}/src/elody/policies/authorization/mediafile_download_policy.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|