From 58d9c272003f490fede7f47dca430a4b420698e4 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Tue, 6 Jul 2021 14:52:17 +0200
Subject: [PATCH] =?UTF-8?q?Jobs:=20N=C4=9Bkter=C3=A9=20joby=20mohou=20expi?=
=?UTF-8?q?rovat=20po=20del=C5=A1=C3=AD=20dob=C4=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
etc/config.py.example | 3 +++
mo/jobs/__init__.py | 6 +++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/etc/config.py.example b/etc/config.py.example
index af31c885..b0bf3825 100644
--- a/etc/config.py.example
+++ b/etc/config.py.example
@@ -48,6 +48,9 @@ GC_PERIOD = 60
# Za jak dlouho expiruje dokončená dávka [min]
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
REG_MAX_PER_MINUTE = 10
diff --git a/mo/jobs/__init__.py b/mo/jobs/__init__.py
index e443573e..2d7da1a0 100644
--- a/mo/jobs/__init__.py
+++ b/mo/jobs/__init__.py
@@ -27,6 +27,7 @@ class TheJob:
job_id: Optional[int]
gatekeeper: Optional[mo.rights.Gatekeeper]
errors: List[str]
+ expires_in_minutes: int
def __init__(self, job_id: Optional[int] = None):
"""Pokud chceme pracovat s existujícím jobem, zadáme jeho ID."""
@@ -133,10 +134,13 @@ class TheJob:
job = self.job
logger.info(f'Job: Spouštím job #{job.job_id} ({job.type}) uživatele #{job.user_id}')
job.state = db.JobState.running
+ job.finished_at = None
+ job.expires_at = None
sess.commit()
try:
self.gatekeeper = mo.rights.Gatekeeper(job.user)
+ self.expires_in_minutes = config.JOB_EXPIRATION
_handler_table[job.type](self)
if self.errors:
logger.info(f'Job: Neúspěšně dokončen job #{job.job_id} ({job.result})')
@@ -153,7 +157,7 @@ class TheJob:
job.result = 'Interní chyba, informujte prosím správce systému.'
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()
--
GitLab