1234567891011121314151617181920212223242526272829303132333435363738 |
- from time import time
- from uuid import uuid1
- from pycs.database.Project import Project
- class Job:
- """
- wrapper class to track job data and progress
- """
- # pylint: disable=too-few-public-methods
- def __init__(self, project: Project, job_type: str, name: str):
- self.id = str(uuid1())
- self.project_id = project.id
- self.type = job_type
- self.name = name
- self.exception = None
- self.progress = 0
- self.created = int(time())
- self.updated = int(time())
- self.started = None
- self.finished = None
- def __str__(self):
- return f"<Job {self.type}: name={self.name}, project={self.project_id} progress={self.progress}>"
- def start(self):
- self.started = int(time())
- self.update(progress=0)
- def finish(self):
- self.finished = int(time())
- self.update(progress=1)
- def update(self, progress: float):
- self.progress = progress
- self.updated = int(time())
|