From 9b3b5c1a99d97be1f5928234ba73ca35114963bd Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Sat, 2 Dec 2023 16:03:29 +0000 Subject: [PATCH] chore(jobsystem): add more model fields --- models/jobsystem.model | 36 +++++++++++++++++++++++++++++++++--- src/Model/Types/Common.hs | 6 +++++- src/Model/Types/Jobsystem.hs | 23 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/models/jobsystem.model b/models/jobsystem.model index a5b0902f2..d8970b451 100644 --- a/models/jobsystem.model +++ b/models/jobsystem.model @@ -2,9 +2,39 @@ -- assigned to the workers -- part of the *new* job system JobMeta - occurrence JobOccurrence -- When should the job be executed? - -- (Possibly recurring) - ressources JobRessources + occurrence JobOccurrence -- When should the job be executed? + -- (Possibly recurring) + relativeInTime TimeRelative Maybe -- TODO find better name + planExecutionAhead NominalDiffTime -- TODO find better name + executionTimeEpsilon NominalDiffTime Maybe + priority JobPriority + ressources JobRessources + status JobStatus + lastStartSystem LocalTime Maybe -- when did a job scheduler last order + -- a job worker to execute this job? + -- when a job is to be executed now, + -- lastStartWorker and lastFinished + -- are unset + lastStartWorker LocalTime Maybe -- when did a job worker last start + -- executing this job? + -- when no time is set, the job either + -- was never executed yet or execution + -- was just ordered (or something went + -- very wrong within the jobsystem) + lastFinished LocalTime Maybe -- when did a job worker last report + -- successful execution? + -- all "last..." fields should be set by the scheduler atomically! + retryAfter NominalDiffTime Maybe -- if set, the scheduler checks on + -- the job after this time and retries + -- the job iff lastStartWorker is set, + -- but lastFinished is unset + -- Ensure that retryAfter is sufficient + -- for this job and application, so better + -- set to higher values until we know this + -- job is definitely dead after execution + -- (pun intended) + isSystemJob Bool -- new system jobs are to be scheduled, old system jobs to be deleted on migration + appVersion AppVersion deriving Eq Ord Show Generic -- Actual job to be fetched and executed by the workers diff --git a/src/Model/Types/Common.hs b/src/Model/Types/Common.hs index 836d2741e..91087526d 100644 --- a/src/Model/Types/Common.hs +++ b/src/Model/Types/Common.hs @@ -1,4 +1,4 @@ --- SPDX-FileCopyrightText: 2022 Gregor Kleen ,Sarah Vaupel ,Sarah Vaupel ,Steffen Jost +-- SPDX-FileCopyrightText: 2022-2023 Sarah Vaupel , Gregor Kleen ,Sarah Vaupel ,Sarah Vaupel ,Steffen Jost -- -- SPDX-License-Identifier: AGPL-3.0-or-later @@ -16,6 +16,8 @@ import Import.NoModel import qualified Yesod.Auth.Util.PasswordStore as PWStore +import qualified Data.SemVer as SemVer + type Count = Sum Integer type Points = Centi @@ -67,3 +69,5 @@ type SessionFileReference = Digest SHA3_256 type QualificationName = CI Text type QualificationShorthand = CI Text + +type AppVersion = SemVer.Version diff --git a/src/Model/Types/Jobsystem.hs b/src/Model/Types/Jobsystem.hs index 4082a3372..155dd5209 100644 --- a/src/Model/Types/Jobsystem.hs +++ b/src/Model/Types/Jobsystem.hs @@ -1,10 +1,19 @@ module Model.Types.Jobsystem ( JobOccurrence(..) + , JobPriority(..) , JobRessource(..), JobRessources(..) + , module Jobsys.Basics ) where import Import.NoModel +import Jobsys.Basics (TimeRelative, JobStatus) + + +nullaryPathPiece ''TimeRelative $ camelToPathPiece' 2 +pathPieceJSON ''TimeRelative +derivePersistFieldJSON ''TimeRelative + newtype JobOccurrence = JobOccurrence { jobOccurrence :: Occurrence LocalTime () -- latter is specialtime; not used yet @@ -19,6 +28,20 @@ deriveJSON defaultOptions derivePersistFieldJSON ''JobOccurrence +-- | Priorities of jobs to be executed. Note that Top < ... < Least must hold, so be careful with constructor order! +data JobPriority + = JobPrioTop + | JobPrioHigh + | JobPrioMedium + | JobPrioLow + | JobPrioLeast + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) + deriving anyclass (Universe, Finite, NFData) + +nullaryPathPiece ''JobPriority $ camelToPathPiece' 2 +pathPieceJSON ''JobPriority + + data JobRessource = JobResCPU | JobResMemory