Job.py 1003 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. from time import time
  2. from uuid import uuid1
  3. from pycs.database.Project import Project
  4. class Job:
  5. """
  6. wrapper class to track job data and progress
  7. """
  8. # pylint: disable=too-few-public-methods
  9. def __init__(self, project: Project, job_type: str, name: str):
  10. self.id = str(uuid1())
  11. self.project_id = project.id
  12. self.type = job_type
  13. self.name = name
  14. self.exception = None
  15. self.progress = 0
  16. self.created = int(time())
  17. self.updated = int(time())
  18. self.started = None
  19. self.finished = None
  20. def __str__(self):
  21. return f"<Job {self.type}: name={self.name}, project={self.project_id} progress={self.progress}>"
  22. def start(self):
  23. self.started = int(time())
  24. self.update(progress=0)
  25. def finish(self):
  26. self.finished = int(time())
  27. self.update(progress=1)
  28. def update(self, progress: float):
  29. self.progress = progress
  30. self.updated = int(time())