Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
195
Issues
195
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
c6497333
Commit
c6497333
authored
Apr 17, 2023
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/adinapoli/issue-198' into dev-merge
parents
88e83dc9
3435b69d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
20 deletions
+38
-20
Main.hs
tests/queue/Main.hs
+38
-20
No files found.
tests/queue/Main.hs
View file @
c6497333
...
@@ -12,9 +12,10 @@ import Control.Exception
...
@@ -12,9 +12,10 @@ import Control.Exception
import
Control.Monad
import
Control.Monad
import
Control.Monad.Reader
import
Control.Monad.Reader
import
Control.Monad.Except
import
Control.Monad.Except
import
Data.Maybe
import
Data.Either
import
Data.Either
import
Data.List
import
Data.List
import
Data.Sequence
(
Seq
)
import
Data.Sequence
(
Seq
,
(
|>
),
fromList
)
import
GHC.Stack
import
GHC.Stack
import
Prelude
import
Prelude
import
System.IO.Unsafe
import
System.IO.Unsafe
...
@@ -33,7 +34,20 @@ import Gargantext.API.Prelude
...
@@ -33,7 +34,20 @@ import Gargantext.API.Prelude
import
Gargantext.API.Admin.EnvTypes
as
EnvTypes
import
Gargantext.API.Admin.EnvTypes
as
EnvTypes
import
Gargantext.API.Admin.Orchestrator.Types
import
Gargantext.API.Admin.Orchestrator.Types
data
JobT
=
A
|
B
deriving
(
Eq
,
Ord
,
Show
,
Enum
,
Bounded
)
data
JobT
=
A
|
B
|
C
|
D
deriving
(
Eq
,
Ord
,
Show
,
Enum
,
Bounded
)
-- | This type models the schedule picked up by the orchestrator.
newtype
JobSchedule
=
JobSchedule
{
_JobSchedule
::
Seq
JobT
}
deriving
(
Eq
,
Show
)
addJobToSchedule
::
JobT
->
MVar
JobSchedule
->
IO
()
addJobToSchedule
jobt
mvar
=
do
modifyMVar_
mvar
$
\
js
->
do
let
js'
=
js
{
_JobSchedule
=
_JobSchedule
js
|>
jobt
}
pure
js'
data
Counts
=
Counts
{
countAs
::
Int
,
countBs
::
Int
}
data
Counts
=
Counts
{
countAs
::
Int
,
countBs
::
Int
}
deriving
(
Eq
,
Show
)
deriving
(
Eq
,
Show
)
...
@@ -41,8 +55,12 @@ data Counts = Counts { countAs :: Int, countBs :: Int }
...
@@ -41,8 +55,12 @@ data Counts = Counts { countAs :: Int, countBs :: Int }
inc
,
dec
::
JobT
->
Counts
->
Counts
inc
,
dec
::
JobT
->
Counts
->
Counts
inc
A
cs
=
cs
{
countAs
=
countAs
cs
+
1
}
inc
A
cs
=
cs
{
countAs
=
countAs
cs
+
1
}
inc
B
cs
=
cs
{
countBs
=
countBs
cs
+
1
}
inc
B
cs
=
cs
{
countBs
=
countBs
cs
+
1
}
inc
C
cs
=
cs
inc
D
cs
=
cs
dec
A
cs
=
cs
{
countAs
=
countAs
cs
-
1
}
dec
A
cs
=
cs
{
countAs
=
countAs
cs
-
1
}
dec
B
cs
=
cs
{
countBs
=
countBs
cs
-
1
}
dec
B
cs
=
cs
{
countBs
=
countBs
cs
-
1
}
dec
C
cs
=
cs
dec
D
cs
=
cs
jobDuration
,
initialDelay
::
Int
jobDuration
,
initialDelay
::
Int
jobDuration
=
100000
jobDuration
=
100000
...
@@ -75,29 +93,29 @@ testPrios :: IO ()
...
@@ -75,29 +93,29 @@ testPrios :: IO ()
testPrios
=
do
testPrios
=
do
k
<-
genSecret
k
<-
genSecret
let
settings
=
defaultJobSettings
2
k
let
settings
=
defaultJobSettings
2
k
prios
=
[(
B
,
10
),
(
C
,
1
),
(
D
,
5
)]
runningDelta
job
=
fromMaybe
0
(
lookup
job
prios
)
*
1000
st
::
JobsState
JobT
[
String
]
()
<-
newJobsState
settings
$
st
::
JobsState
JobT
[
String
]
()
<-
newJobsState
settings
$
applyPrios
[(
B
,
10
)]
defaultPrios
-- B has higher
priority
applyPrios
prios
defaultPrios
-- B has the highest
priority
runningJs
<-
newTVarIO
(
Counts
0
0
)
pickedSchedule
<-
newMVar
(
JobSchedule
mempty
)
let
j
jobt
_jHandle
_inp
_l
=
do
let
j
jobt
_jHandle
_inp
_l
=
do
atomically
$
modifyTVar
runningJs
(
inc
jobt
)
-- simulate the running time of a job, then add to the schedule.
threadDelay
jobDuration
-- The running time is proportional to the priority of the job,
atomically
$
modifyTVar
runningJs
(
dec
jobt
)
-- to account for the fact that we are pushing jobs sequentially,
-- so we have to our account for the submission time.
threadDelay
$
jobDuration
-
runningDelta
jobt
addJobToSchedule
jobt
pickedSchedule
jobs
=
[
(
A
,
j
A
)
jobs
=
[
(
A
,
j
A
)
,
(
A
,
j
A
)
,
(
C
,
j
C
)
,
(
B
,
j
B
)
,
(
B
,
j
B
)
,
(
B
,
j
B
)
,
(
D
,
j
D
)
]
]
_jids
<-
forM
jobs
$
\
(
t
,
f
)
->
do
forM_
jobs
$
\
(
t
,
f
)
->
void
$
pushJob
t
()
f
settings
st
pushJob
t
()
f
settings
st
-- wait for the jobs to finish, waiting for more than the total duration,
threadDelay
(
2
*
initialDelay
)
-- so that we are sure that all jobs have finished, then check the schedule.
r1
<-
readTVarIO
runningJs
threadDelay
(
5
*
jobDuration
)
r1
`
shouldBe
`
(
Counts
0
2
)
finalSchedule
<-
readMVar
pickedSchedule
threadDelay
jobDuration
finalSchedule
`
shouldBe
`
JobSchedule
(
fromList
[
B
,
D
,
C
,
A
])
r2
<-
readTVarIO
runningJs
r2
`
shouldBe
`
(
Counts
2
0
)
threadDelay
jobDuration
r3
<-
readTVarIO
runningJs
r3
`
shouldBe
`
(
Counts
0
0
)
testExceptions
::
IO
()
testExceptions
::
IO
()
testExceptions
=
do
testExceptions
=
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment