ProcessDBTasks.icl 4.35 KB
Newer Older
1 2
implementation module ProcessDBTasks

3
import StdOverloaded, StdClass, StdInt, StdArray, StdTuple, StdList
4 5
import TSt

Steffen Michels's avatar
Steffen Michels committed
6
from ProcessDB import :: Process{..}, :: ProcessStatus(..), :: Menu
7 8 9 10 11
from ProcessDB import qualified class ProcessDB(..)
from ProcessDB import qualified instance ProcessDB TSt

from UserDB import getUser

12
from Types	import :: ProcessId, :: ProcessRef
13 14 15 16 17 18

import Time
import CommonCombinators

import Store

19 20 21 22 23 24
derive gVisualize	ProcessRef, Process, ProcessStatus, TaskProperties, SystemProperties, ManagerProperties, WorkerProperties, TaskPriority, TaskProgress, Timestamp, TaskParallelType
derive gUpdate		ProcessRef, Process, ProcessStatus, TaskProperties, SystemProperties, ManagerProperties, WorkerProperties, TaskPriority, TaskProgress, Timestamp, TaskParallelType
derive gPrint		ProcessRef, Process, ProcessStatus, TaskProperties, SystemProperties, ManagerProperties, WorkerProperties, TaskPriority, TaskProgress, Timestamp, TaskParallelType
derive gParse		ProcessRef, Process, ProcessStatus, TaskProperties, SystemProperties, ManagerProperties, WorkerProperties, TaskPriority, TaskProgress, Timestamp, TaskParallelType
derive gError		ProcessRef, Process, ProcessStatus, TaskProperties, SystemProperties, ManagerProperties, WorkerProperties, TaskPriority, TaskProgress, Timestamp, TaskParallelType
derive gHint		ProcessRef, Process, ProcessStatus, TaskProperties, SystemProperties, ManagerProperties, WorkerProperties, TaskPriority, TaskProgress, Timestamp, TaskParallelType
25

26 27
derive bimap	Maybe, (,)

28 29 30 31 32 33 34 35 36 37 38
class toProcessId a where toProcessId :: a -> ProcessId

instance toProcessId ProcessId
where
	toProcessId pid = pid
	
instance toProcessId (ProcessRef a)
where
	toProcessId (ProcessRef pid) = pid

getProcess :: !pid -> Task (Maybe Process) | toProcessId pid
39
getProcess pid = mkInstantTask "getProcess" (mkTaskFunction (\tst -> ProcessDB@getProcess (toProcessId pid) tst))
40

41 42
getProcessForUser :: !User !pid -> Task (Maybe Process) | toProcessId pid
getProcessForUser user pid = mkInstantTask "getProcessForUser" (mkTaskFunction (\tst -> ProcessDB@getProcessForUser user (toProcessId pid) tst))
43 44

getProcesses :: ![pid] -> Task [Process] | toProcessId pid
45
getProcesses ids = mkInstantTask "getProcessesById" (mkTaskFunction (\tst -> ProcessDB@getProcessesById (map toProcessId ids) tst))
46 47

getProcessesWithStatus :: ![ProcessStatus] -> Task [Process]
48
getProcessesWithStatus statuses = mkInstantTask "getProcesses" (mkTaskFunction (\tst -> ProcessDB@getProcesses statuses tst))
49

50 51
getProcessesForUser	:: !User ![ProcessStatus] -> Task [Process]
getProcessesForUser user statuses = mkInstantTask "getProcessesForUser" (mkTaskFunction (\tst -> ProcessDB@getProcessesForUser user statuses tst))
52

53
getProcessOwner :: !pid -> Task (Maybe User) | toProcessId pid
54 55 56 57
getProcessOwner pid = mkInstantTask "getProcess" getProcessStatus`
where
	getProcessStatus` tst 
	# (process,tst)	= ProcessDB@getProcess (toProcessId pid) tst
58
	# owner 		= if (isNothing process) Nothing (Just (fromJust process).Process.properties.managerProps.ManagerProperties.worker)
59
	= (TaskFinished owner,tst)
60
	
61 62
setProcessOwner :: !User !pid -> Task Void | toProcessId pid
setProcessOwner user pid = mkInstantTask "setProcessOwner" setProcessOwner`
63
where
64
	setProcessOwner` tst=:{staticInfo}
65
		# (_,tst)			= ProcessDB@setProcessOwner user (toProcessId pid) tst
66
		= (TaskFinished Void,tst)
67 68 69 70 71 72 73

getProcessStatus :: !pid -> Task ProcessStatus | toProcessId pid
getProcessStatus pid = mkInstantTask "getProcessStatus" getProcessStatus`
where
	getProcessStatus` tst
		# (mbProcess,tst)	= ProcessDB@getProcess (toProcessId pid) tst
		= case mbProcess of
74 75
			Just {Process | status}	= (TaskFinished status, tst)
			Nothing					= (TaskFinished Deleted, tst)
76 77
			

78
activateProcess	:: !pid	-> Task Void | toProcessId pid
79 80
activateProcess pid = mkInstantTask "activateProcess" activateProcess`
where
81
	activateProcess` tst
82 83
		# (_,tst)	= ProcessDB@setProcessStatus Active (toProcessId pid) tst
		= (TaskFinished Void,tst)
84
		
85
suspendProcess :: !pid -> Task Void	| toProcessId pid
86 87
suspendProcess pid = mkInstantTask "suspendProcess" suspendProcess`
where
88
	suspendProcess` tst
89 90
		# (_,tst)	= ProcessDB@setProcessStatus Suspended (toProcessId pid) tst
		= (TaskFinished Void,tst)
91
		
92
deleteProcess :: pid -> Task Void | toProcessId pid
93 94
deleteProcess pid = mkInstantTask "deleteProcess" deleteProcess`
where
95
	deleteProcess` tst
96 97
		# (_,tst)	= ProcessDB@deleteProcess (toProcessId pid) tst
		= (TaskFinished Void,tst)