Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
iTasks-SDK
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
84
Issues
84
List
Boards
Labels
Service Desk
Milestones
Merge Requests
10
Merge Requests
10
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
clean-and-itasks
iTasks-SDK
Commits
890b8228
Commit
890b8228
authored
Oct 15, 2016
by
Mart Lubbers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add functionality to dynamically add and remove background tasks
parent
ced4ec10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
Server/iTasks/_Framework/IWorld.dcl
Server/iTasks/_Framework/IWorld.dcl
+8
-1
Server/iTasks/_Framework/TaskServer.dcl
Server/iTasks/_Framework/TaskServer.dcl
+7
-1
Server/iTasks/_Framework/TaskServer.icl
Server/iTasks/_Framework/TaskServer.icl
+26
-8
No files found.
Server/iTasks/_Framework/IWorld.dcl
View file @
890b8228
...
...
@@ -92,7 +92,7 @@ from TCPIP import :: TCP_Listener, :: TCP_Listener_, :: TCP_RChannel_, :: TCP_SC
::
*
IOTaskInstance
=
ListenerInstance
!
ListenerInstanceOpts
!*
TCP_Listener
|
ConnectionInstance
!
ConnectionInstanceOpts
!*
TCP_DuplexChannel
|
BackgroundInstance
!
BackgroundTask
|
BackgroundInstance
!
Background
InstanceOpts
!
Background
Task
::
ListenerInstanceOpts
=
{
taskId
::
!
TaskId
//Reference to the task that created the listener
...
...
@@ -112,6 +112,13 @@ from TCPIP import :: TCP_Listener, :: TCP_Listener_, :: TCP_RChannel_, :: TCP_SC
::
ConnectionId
:==
Int
::
BackgroundInstanceOpts
=
{
bgInstId
::
!
BackgroundTaskId
}
::
BackgroundTaskId
:==
Int
::
IOStates
:==
Map
TaskId
IOState
::
IOState
=
IOActive
!(
Map
ConnectionId
(!
Dynamic
,!
Bool
))
...
...
Server/iTasks/_Framework/TaskServer.dcl
View file @
890b8228
...
...
@@ -8,7 +8,7 @@ from Internet.HTTP import :: HTTPRequest, :: HTTPResponse
from
System
.
Time
import
::
Timestamp
from
Data
.
Error
import
::
MaybeError
from
iTasks
.
API
.
Core
.
Types
import
::
TaskId
from
iTasks
.
_Framework
.
IWorld
import
::
IWorld
from
iTasks
.
_Framework
.
IWorld
import
::
IWorld
,
::
BackgroundTaskId
from
iTasks
.
_Framework
.
Task
import
::
ConnectionTask
,
::
BackgroundTask
,
::
TaskException
from
iTasks
.
_Framework
.
Engine
import
::
ConnectionType
...
...
@@ -20,3 +20,9 @@ addListener :: !TaskId !Int !Bool !ConnectionTask !*IWorld -> (!MaybeError TaskE
//Dynamically add a connection
addConnection
::
!
TaskId
!
String
!
Int
!
ConnectionTask
!*
IWorld
->
(!
MaybeError
TaskException
(),!*
IWorld
)
//Dynamically add a background task
addBackgroundTask
::
!
BackgroundTaskId
!
BackgroundTask
!*
IWorld
->
(!
MaybeError
TaskException
(),!*
IWorld
)
//Dynamically remove a background task
removeBackgroundTask
::
!
BackgroundTaskId
!*
IWorld
->
(!
MaybeError
TaskException
(),!*
IWorld
)
Server/iTasks/_Framework/TaskServer.icl
View file @
890b8228
...
...
@@ -18,7 +18,7 @@ import iTasks._Framework.TaskEval
::
*
IOTaskInstanceDuringSelect
=
ListenerInstanceDS
!
ListenerInstanceOpts
|
ConnectionInstanceDS
!
ConnectionInstanceOpts
!*
TCP_SChannel
|
BackgroundInstanceDS
!
BackgroundTask
|
BackgroundInstanceDS
!
Background
InstanceOpts
!
Background
Task
serve
::
!
Int
!
ConnectionTask
![
BackgroundTask
]
(*
IWorld
->
(!
Maybe
Timeout
,!*
IWorld
))
*
IWorld
->
*
IWorld
serve
port
ct
bt
determineTimeout
iworld
...
...
@@ -30,7 +30,7 @@ init port ct bt iworld=:{IWorld|ioTasks,world}
|
not
success
=
abort
(
"Error: port "
+++
toString
port
+++
" already in use.
\n
"
)
#
opts
=
{
ListenerInstanceOpts
|
taskId
=
TaskId
0
0
,
nextConnectionId
=
0
,
port
=
port
,
connectionTask
=
ct
,
removeOnClose
=
True
}
#
ioStates
=
'
DM
'.
fromList
[(
TaskId
0
0
,
IOActive
'
DM
'.
newMap
)]
=
{
iworld
&
ioTasks
=
{
done
=[],
todo
=[
ListenerInstance
opts
(
fromJust
mbListener
):
map
BackgroundInstance
bt
]},
ioStates
=
ioStates
,
world
=
world
}
=
{
iworld
&
ioTasks
=
{
done
=[],
todo
=[
ListenerInstance
opts
(
fromJust
mbListener
):
map
(
BackgroundInstance
{
bgInstId
=
0
})
bt
]},
ioStates
=
ioStates
,
world
=
world
}
loop
::
!(*
IWorld
->
(!
Maybe
Timeout
,!*
IWorld
))
!*
IWorld
->
*
IWorld
loop
determineTimeout
iworld
...
...
@@ -62,7 +62,7 @@ toSelectSet [i:is]
=
case
i
of
ListenerInstance
opts
l
=
([
l
:
ls
],
rs
,[
ListenerInstanceDS
opts
:
is
])
ConnectionInstance
opts
{
rChannel
,
sChannel
}
=
(
ls
,[
rChannel
:
rs
],[
ConnectionInstanceDS
opts
sChannel
:
is
])
BackgroundInstance
bt
=
(
ls
,
rs
,[
BackgroundInstanceDS
bt
:
is
])
BackgroundInstance
opts
bt
=
(
ls
,
rs
,[
BackgroundInstanceDS
opts
bt
:
is
])
/* Restore the list of main loop instances.
In the same pass also update the indices in the select result to match the
...
...
@@ -98,9 +98,9 @@ where
#
(
is
,
ch
)
=
fromSelectSet`
(
i
+1
)
numListeners
numSeenListeners
(
numSeenReceivers
+1
)
ls
rs
[(
c
,
what
):
ch
]
is
=
([
ConnectionInstance
opts
{
rChannel
=
rChannel
,
sChannel
=
sChannel
}:
is
],
ch
)
//Background tasks
fromSelectSet`
i
numListeners
numSeenListeners
numSeenReceivers
ls
rs
ch
[
BackgroundInstanceDS
bt
:
is
]
fromSelectSet`
i
numListeners
numSeenListeners
numSeenReceivers
ls
rs
ch
[
BackgroundInstanceDS
opts
bt
:
is
]
#
(
is
,
ch
)
=
fromSelectSet`
(
i
+1
)
numListeners
numSeenListeners
numSeenReceivers
ls
rs
ch
is
=
([
BackgroundInstance
bt
:
is
],
ch
)
=
([
BackgroundInstance
opts
bt
:
is
],
ch
)
ulength
[]
=
(
0
,[])
ulength
[
x
:
xs
]
...
...
@@ -262,9 +262,9 @@ process i chList iworld=:{ioTasks={done,todo=[ConnectionInstance opts {rChannel,
#
world
=
closeChannel
sChannel
world
=
process
(
i
+1
)
chList
{
iworld
&
ioTasks
={
done
=
done
,
todo
=
todo
},
ioStates
=
ioStates
,
world
=
world
}
process
i
chList
iworld
=:{
ioTasks
={
done
,
todo
=[
BackgroundInstance
bt
=:(
BackgroundTask
eval
):
todo
]}}
process
i
chList
iworld
=:{
ioTasks
={
done
,
todo
=[
BackgroundInstance
opts
bt
=:(
BackgroundTask
eval
):
todo
]}}
#
iworld
=:{
ioTasks
={
done
,
todo
}}
=
eval
{
iworld
&
ioTasks
=
{
done
=
done
,
todo
=
todo
}}
=
process
(
i
+1
)
chList
{
iworld
&
ioTasks
={
done
=[
BackgroundInstance
bt
:
done
],
todo
=
todo
}}
=
process
(
i
+1
)
chList
{
iworld
&
ioTasks
={
done
=[
BackgroundInstance
opts
bt
:
done
],
todo
=
todo
}}
process
i
chList
iworld
=:{
ioTasks
={
done
,
todo
=[
t
:
todo
]}}
=
process
(
i
+1
)
chList
{
iworld
&
ioTasks
={
done
=[
t
:
done
],
todo
=
todo
}}
...
...
@@ -319,6 +319,24 @@ addConnection taskId=:(TaskId instanceNo _) host port connectionTask iworld=:{io
Error
e
=
'
DM
'.
put
taskId
(
IOException
e
)
ioStates
=
(
Ok
(),{
iworld
&
ioTasks
=
{
done
=
done
,
todo
=
todo
},
ioStates
=
ioStates
,
world
=
world
})
//Dynamically add a background task
addBackgroundTask
::
!
BackgroundTaskId
!
BackgroundTask
!*
IWorld
->
(!
MaybeError
TaskException
(),!*
IWorld
)
addBackgroundTask
btid
bt
iworld
=:{
ioTasks
={
done
,
todo
}}
#
todo
=
todo
++
[
BackgroundInstance
{
BackgroundInstanceOpts
|
bgInstId
=
btid
}
bt
]
=
(
Ok
(),
{
iworld
&
ioTasks
={
done
=
done
,
todo
=
todo
}})
//Dynamically remove a background task
removeBackgroundTask
::
!
BackgroundTaskId
!*
IWorld
->
(!
MaybeError
TaskException
(),!*
IWorld
)
removeBackgroundTask
btid
iworld
=:{
ioTasks
={
done
,
todo
}}
//We filter the tasks and use the boolean state to hold whether a task was dropped
#
(
r
,
todo
)
=
foldr
(\
e
(
b
,
l
)->
let
(
b`
,
e`
)=
drop
e
in
(
b`
||
b
,
if
b`
l
[
e`
:
l
]))
(
False
,
[])
todo
#
iworld
=
{
iworld
&
ioTasks
={
done
=
done
,
todo
=
todo
}}
|
not
r
=
(
Error
(
exception
"No backgroundtask with that id"
),
iworld
)
=
(
Ok
(),
iworld
)
where
drop
a
=:(
BackgroundInstance
{
bgInstId
}
_)
=
(
bgInstId
==
btid
,
a
)
drop
a
=
(
False
,
a
)
checkSelect
::
!
Int
![(!
Int
,!
SelectResult
)]
->
(!
Maybe
SelectResult
,![(!
Int
,!
SelectResult
)])
checkSelect
i
chList
=:[(
who
,
what
):
ws
]
|
(
i
==
who
)
=
(
Just
what
,
ws
)
checkSelect
i
chList
=
(
Nothing
,
chList
)
...
...
@@ -332,6 +350,6 @@ halt iworld=:{ioTasks={todo=[ConnectionInstance _ {rChannel,sChannel}:todo],done
#
world
=
closeRChannel
rChannel
world
#
world
=
closeChannel
sChannel
world
=
halt
{
iworld
&
ioTasks
=
{
todo
=
todo
,
done
=
done
}}
halt
iworld
=:{
ioTasks
={
todo
=[
BackgroundInstance
_
:
todo
],
done
},
world
}
halt
iworld
=:{
ioTasks
={
todo
=[
BackgroundInstance
_
_
:
todo
],
done
},
world
}
=
halt
{
iworld
&
ioTasks
=
{
todo
=
todo
,
done
=
done
}}
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