_job_model.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. from dataclasses import dataclass
  12. from typing import Any, Dict, List
  13. from .._repository._base_taipy_model import _BaseModel
  14. from .job_id import JobId
  15. from .status import Status
  16. @dataclass
  17. class _JobModel(_BaseModel):
  18. id: JobId
  19. task_id: str
  20. status: Status
  21. force: bool
  22. submit_id: str
  23. submit_entity_id: str
  24. creation_date: str
  25. execution_started_at: str
  26. execution_ended_at: str
  27. subscribers: List[Dict]
  28. stacktrace: List[str]
  29. version: str
  30. @staticmethod
  31. def from_dict(data: Dict[str, Any]):
  32. return _JobModel(
  33. id=data["id"],
  34. task_id=data["task_id"],
  35. status=Status._from_repr(data["status"]),
  36. force=data["force"],
  37. submit_id=data["submit_id"],
  38. submit_entity_id=data["submit_entity_id"],
  39. creation_date=data["creation_date"],
  40. execution_started_at=data["execution_started_at"],
  41. execution_ended_at=data["execution_ended_at"],
  42. subscribers=_BaseModel._deserialize_attribute(data["subscribers"]),
  43. stacktrace=_BaseModel._deserialize_attribute(data["stacktrace"]),
  44. version=data["version"],
  45. )
  46. def to_list(self):
  47. return [
  48. self.id,
  49. self.task_id,
  50. repr(self.status),
  51. self.force,
  52. self.submit_id,
  53. self.submit_entity_id,
  54. self.creation_date,
  55. self.execution_started_at,
  56. self.execution_ended_at,
  57. _BaseModel._serialize_attribute(self.subscribers),
  58. _BaseModel._serialize_attribute(self.stacktrace),
  59. self.version,
  60. ]