From 36a53d3daefb326fd3d48b1bb1643a22f4868482 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Thu, 2 Nov 2023 20:49:05 +0000 Subject: [PATCH] chore(jobsystem): add dependencies, work on first model defs --- models/jobs.model | 3 +++ models/jobsystem.model | 5 ++++ package.yaml | 3 +++ src/Import/NoModel.hs | 3 ++- src/JobSystem.hs | 13 ++++++---- src/Model/Types.hs | 1 + src/Model/Types/Jobsystem.hs | 9 +++++++ stack.yaml | 15 ++++++++++- stack.yaml.lock | 49 ++++++++++++++++++++++++++++++++---- 9 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 models/jobsystem.model create mode 100644 src/Model/Types/Jobsystem.hs diff --git a/models/jobs.model b/models/jobs.model index 98aa8c3b8..2828f1c23 100644 --- a/models/jobs.model +++ b/models/jobs.model @@ -3,6 +3,7 @@ -- SPDX-License-Identifier: AGPL-3.0-or-later -- Jobs to be executed as soon as possible in the background (so not to delay HTTP-responses, or triggered by cron-system without associated HTTP-Request) +-- part of the *old* job system QueuedJob content Value -- JSON-encoded description of the work to be done (send an email to "test@example.org", find all recipients for a certain notifications and queue one new job each, distribute all submissions for a sheet to correctors, ...) creationInstance InstanceId -- multiple uni2work-instances access the same database, record which instance created this job for debugging purposes @@ -15,6 +16,7 @@ QueuedJob -- Jobs are deleted from @QueuedJob@ after they are executed successfully and recorded in @CronLastExec@ -- There is a Cron-system that, at set intervals, queries the database for work to be done in the background (i.e. if a lecturer has set a sheet's submissions to be automatically distributed and the submission deadline passed since the last check, then queue a new job to actually do the distribution) -- For the cron-system to determine whether a job needs to be done it needs to know if and when it was last (or ever) executed (i.e. a sheet's submissions should not be distributed twice) +-- part of the *old* job system CronLastExec job Value -- JSON-encoded description of work done time UTCTime -- When was the job executed @@ -22,6 +24,7 @@ CronLastExec UniqueCronLastExec job deriving Generic +-- part of the *old* job system TokenBucket ident TokenBucketIdent lastValue Int64 diff --git a/models/jobsystem.model b/models/jobsystem.model new file mode 100644 index 000000000..af5fccddd --- /dev/null +++ b/models/jobsystem.model @@ -0,0 +1,5 @@ +-- Jobs to be fetched and distributed to the workers by the scheduler +-- part of the *new* job system +JobMeta + occurrence JobOccurrence default='{"dnf-terms":[]}' -- when should the job be executed? (Possibly recurring) + deriving Eq Ord Show Generic diff --git a/package.yaml b/package.yaml index 7433e38f9..739f27881 100644 --- a/package.yaml +++ b/package.yaml @@ -187,6 +187,9 @@ dependencies: - either - xlsx - jobsys + - occurrence + - segmented + - haskell-nf other-extensions: - GeneralizedNewtypeDeriving - IncoherentInstances diff --git a/src/Import/NoModel.hs b/src/Import/NoModel.hs index 90edef7a1..b0ab2f01f 100644 --- a/src/Import/NoModel.hs +++ b/src/Import/NoModel.hs @@ -262,9 +262,10 @@ import Data.MultiSet as Import (MultiSet) import Data.MonoTraversable.Keys as Import - import Control.Monad.Trans.RWS (RWST) +import Data.Occurrence as Import (Occurrence) + type MForm m = RWST (Maybe (Env, FileEnv), HandlerSite m, [Lang]) Enctype Ints m diff --git a/src/JobSystem.hs b/src/JobSystem.hs index 09f600c70..44addd3c6 100644 --- a/src/JobSystem.hs +++ b/src/JobSystem.hs @@ -6,9 +6,12 @@ module JobSystem ( ) where --- TODO: add gitlab.uniworx.de/barth/jobsys as dependency to be able to import JobSchedulerWorld and its function -import Jobsys.JobSystem +-- import Jobsys.JobSystem --- TODO: define JobSchedulerWorld instance for managing job workers, scheduler, and communation in-between --- instance JobSchedulerWorld world where --- ... + +-- instance JobSchedulerWorld _world where +-- type Priorities _world = Int +-- type JobId _world = () +-- type Ressource _world = () +-- type Version _world = () +-- type WorkerId _world = () diff --git a/src/Model/Types.hs b/src/Model/Types.hs index c3cd32a20..aef2ab147 100644 --- a/src/Model/Types.hs +++ b/src/Model/Types.hs @@ -31,3 +31,4 @@ import Model.Types.Lms as Types import Model.Types.Avs as Types import Model.Types.Communication as Types import Model.Types.SystemMessage as Types +import Model.Types.Jobsystem as Types diff --git a/src/Model/Types/Jobsystem.hs b/src/Model/Types/Jobsystem.hs new file mode 100644 index 000000000..9404307a5 --- /dev/null +++ b/src/Model/Types/Jobsystem.hs @@ -0,0 +1,9 @@ +module Model.Types.Jobsystem + ( JobOccurrence + ) where + +import Import.NoModel + +type JobOccurrence = Occurrence LocalTime () -- latter is specialtime; not used yet + +derivePersistFieldJSON ''Occurrence LocalTime () diff --git a/stack.yaml b/stack.yaml index c471a0150..9c511c70c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -121,9 +121,22 @@ extra-deps: - persistent-postgresql-2.13.0.3@sha256:43384bf8ed9c931c673e6abb763c8811113d1b7004095faaae1eb42e2cd52d8f,3601 - git: https://gitlab.uniworx.de/barth/jobsys.git - commit: 027e9b9a6c38c4f1f1dfe1782726887208084184 + commit: f7aa8c32bb28acfab72863c07184154caff75dcd subdirs: - jobsys + - git: https://gitlab.uniworx.de/barth/occurrence.git + commit: ac4babd9a73814332800460ab7ae469285355207 + subdirs: + - occurrence + - git: https://gitlab.uniworx.de/barth/segmented.git + commit: c790d4d350536e21cbbe421000122390ac2f62d0 + subdirs: + - segmented + + - git: https://github.com/savau/haskell-nf.git + commit: 7f1a8715f41778a67655745ce43334328888020b + subdirs: + - haskell-nf resolver: lts-18.0 allow-newer: true diff --git a/stack.yaml.lock b/stack.yaml.lock index 924fd124a..85760e961 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -536,18 +536,57 @@ packages: original: hackage: persistent-postgresql-2.13.0.3@sha256:43384bf8ed9c931c673e6abb763c8811113d1b7004095faaae1eb42e2cd52d8f,3601 - completed: - commit: 027e9b9a6c38c4f1f1dfe1782726887208084184 + commit: f7aa8c32bb28acfab72863c07184154caff75dcd git: https://gitlab.uniworx.de/barth/jobsys.git name: jobsys pantry-tree: - sha256: 1325749c3c5dce631b095567dc8729ac20831058aa0c7486452a36afee0a775a - size: 342 + sha256: ca0c2530b5befa4bb0160fdfd17095ed0bfacc85a622ca8a60949e4c3a89588a + size: 601 subdir: jobsys - version: 0.0.1 + version: 0.1.0 original: - commit: 027e9b9a6c38c4f1f1dfe1782726887208084184 + commit: f7aa8c32bb28acfab72863c07184154caff75dcd git: https://gitlab.uniworx.de/barth/jobsys.git subdir: jobsys +- completed: + commit: ac4babd9a73814332800460ab7ae469285355207 + git: https://gitlab.uniworx.de/barth/occurrence.git + name: occurrence + pantry-tree: + sha256: 93eeceb13a73458fb06a065ff686bc127ac6e0acef6503917cd9edb0050a3764 + size: 301 + subdir: occurrence + version: 0.1.0 + original: + commit: ac4babd9a73814332800460ab7ae469285355207 + git: https://gitlab.uniworx.de/barth/occurrence.git + subdir: occurrence +- completed: + commit: c790d4d350536e21cbbe421000122390ac2f62d0 + git: https://gitlab.uniworx.de/barth/segmented.git + name: segmented + pantry-tree: + sha256: 562c5fdc28a876373f7340427aa6d79b623fe6095c730d7848a2d11cf8d7b3ca + size: 236 + subdir: segmented + version: 0.1.0 + original: + commit: c790d4d350536e21cbbe421000122390ac2f62d0 + git: https://gitlab.uniworx.de/barth/segmented.git + subdir: segmented +- completed: + commit: 7f1a8715f41778a67655745ce43334328888020b + git: https://github.com/savau/haskell-nf.git + name: haskell-nf + pantry-tree: + sha256: 01808a6584d7310d1df4ba90c728d10b35646ffcb711ab6f12b27ed9fbbb311f + size: 314 + subdir: haskell-nf + version: 0.3.1 + original: + commit: 7f1a8715f41778a67655745ce43334328888020b + git: https://github.com/savau/haskell-nf.git + subdir: haskell-nf snapshots: - completed: sha256: c632012da648385b9fa3c29f4e0afd56ead299f1c5528ee789058be410e883c0