Skip to content
Snippets Groups Projects
Commit 58d9c272 authored by Martin Mareš's avatar Martin Mareš
Browse files

Jobs: Některé joby mohou expirovat po delší době

parent 57d28028
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,9 @@ GC_PERIOD = 60 ...@@ -48,6 +48,9 @@ GC_PERIOD = 60
# Za jak dlouho expiruje dokončená dávka [min] # Za jak dlouho expiruje dokončená dávka [min]
JOB_EXPIRATION = 5 JOB_EXPIRATION = 5
# Některé dávky (analýza scanů) mají delší expiraci [min]
JOB_EXPIRATION_LONG = 1440
# Kolik nejvýše dovolujeme registrací za minutu # Kolik nejvýše dovolujeme registrací za minutu
REG_MAX_PER_MINUTE = 10 REG_MAX_PER_MINUTE = 10
......
...@@ -27,6 +27,7 @@ class TheJob: ...@@ -27,6 +27,7 @@ class TheJob:
job_id: Optional[int] job_id: Optional[int]
gatekeeper: Optional[mo.rights.Gatekeeper] gatekeeper: Optional[mo.rights.Gatekeeper]
errors: List[str] errors: List[str]
expires_in_minutes: int
def __init__(self, job_id: Optional[int] = None): def __init__(self, job_id: Optional[int] = None):
"""Pokud chceme pracovat s existujícím jobem, zadáme jeho ID.""" """Pokud chceme pracovat s existujícím jobem, zadáme jeho ID."""
...@@ -133,10 +134,13 @@ class TheJob: ...@@ -133,10 +134,13 @@ class TheJob:
job = self.job job = self.job
logger.info(f'Job: Spouštím job #{job.job_id} ({job.type}) uživatele #{job.user_id}') logger.info(f'Job: Spouštím job #{job.job_id} ({job.type}) uživatele #{job.user_id}')
job.state = db.JobState.running job.state = db.JobState.running
job.finished_at = None
job.expires_at = None
sess.commit() sess.commit()
try: try:
self.gatekeeper = mo.rights.Gatekeeper(job.user) self.gatekeeper = mo.rights.Gatekeeper(job.user)
self.expires_in_minutes = config.JOB_EXPIRATION
_handler_table[job.type](self) _handler_table[job.type](self)
if self.errors: if self.errors:
logger.info(f'Job: Neúspěšně dokončen job #{job.job_id} ({job.result})') logger.info(f'Job: Neúspěšně dokončen job #{job.job_id} ({job.result})')
...@@ -153,7 +157,7 @@ class TheJob: ...@@ -153,7 +157,7 @@ class TheJob:
job.result = 'Interní chyba, informujte prosím správce systému.' job.result = 'Interní chyba, informujte prosím správce systému.'
job.finished_at = mo.util.get_now() job.finished_at = mo.util.get_now()
job.expires_at = job.finished_at + timedelta(minutes=config.JOB_EXPIRATION) job.expires_at = job.finished_at + timedelta(minutes=self.expires_in_minutes)
sess.commit() sess.commit()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment