more on run management

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1708 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-05-01 09:28:23 +00:00
parent 747e65e265
commit 34f20329d7
3 changed files with 48 additions and 16 deletions

View file

@ -1,6 +1,6 @@
==================================== =========================
User tracking in the loops framework User/Interaction tracking
==================================== =========================
($Id$) ($Id$)
@ -92,10 +92,38 @@ We still have access to older runs.
We can also retrieve a run object with the run's data. We can also retrieve a run object with the run's data.
>>> run = tracks.getRun(3) >>> tracks.getRun(runId=3)
>>> run
<Run 3, ..., ..., False> <Run 3, ..., ..., False>
We can also use the taskId for retrieving a task's current run.
>>> tracks.getRun(taskId='a001')
<Run 3, ..., ..., False>
When we stop a run explicitly it is marked as ``finished``.
>>> tracks.stopRun('a001')
3
>>> tracks.getRun(runId=3)
<Run 3, ..., ..., True>
>>> tracks.getRun(runId=3).finished
True
Stopping a run removes it from the set of current runs, so the associated
task hasn't got a current run any longer:
>>> tracks.getRun('a001') is None
True
We can also mark earlier runs by stopping them.
>>> tracks.getRun(runId=2)
<Run 2, ..., ..., False>
>>> tracks.stopRun('a001', 2)
2
>>> tracks.getRun(runId=2)
<Run 2, ..., ..., True>
Fin de partie Fin de partie
============= =============

View file

@ -80,27 +80,30 @@ class TrackingStorage(BTreeContainer):
run.start = run.end = getTimeStamp() run.start = run.end = getTimeStamp()
return runId return runId
def stopRun(self, taskId, runId=0, finish=True): def stopRun(self, taskId=None, runId=0, finish=True):
currentRun = self.currentRuns.get(taskId) if taskId is not None:
runId = runId or currentRun currentRun = self.currentRuns.get(taskId)
if runId and runId == currentRun: runId = runId or currentRun
del self.currentRuns[taskId] if runId and runId == currentRun:
run = self.getRun(runId) del self.currentRuns[taskId]
run = self.getRun(runId=runId)
if run is not None: if run is not None:
run.end = getTimeStamp() run.end = getTimeStamp()
run.finished = finish run.finished = finish
return runId return runId
return 0
def getRun(self, runId=0, taskId=None): def getRun(self, taskId=None, runId=0):
if taskId and not runId: if taskId and not runId:
runId = self.currentRuns.get(taskId) runId = self.currentRuns.get(taskId)
if runId: if runId:
return self.runs.get(runId) return self.runs.get(runId)
return None
def saveUserTrack(self, taskId, runId, userName, data, replace=False): def saveUserTrack(self, taskId, runId, userName, data, replace=False):
if not runId: if not runId:
runId = self.currentRuns.get(taskId) or self.startRun(taskId) runId = self.currentRuns.get(taskId) or self.startRun(taskId)
run = self.getRun(runId) run = self.getRun(runId=runId)
if run is None: if run is None:
raise ValueError('Invalid run: %i.' % runId) raise ValueError('Invalid run: %i.' % runId)
run.end = getTimeStamp() run.end = getTimeStamp()

View file

@ -54,17 +54,18 @@ class ITrackingStorage(Interface):
""" Create a new run for the task given and return its id. """ Create a new run for the task given and return its id.
""" """
def stopRun(taskId, runId=0, finish=True): def stopRun(taskId=None, runId=0, finish=True):
""" Stop/finish a run. """ Stop/finish a run.
If the runId is 0 use the task's current run. If the runId is 0 use the task's current run.
If the run is the task's current one remove it from the set If the run is the task's current one remove it from the set
of current runs. of current runs.
Set the run's ``finished`` flag to the value of the ``finish`` Set the run's ``finished`` flag to the value of the ``finish``
argument. argument.
Return the real runId. Return the real runId; return 0 if there is no run for the
parameters given.
""" """
def getRun(runId, taskId=None): def getRun(taskId=None, runId=0):
""" Return the run object identified by ``runId``. Return None """ Return the run object identified by ``runId``. Return None
if there is no corresponding run. if there is no corresponding run.
If ``runId`` is 0 and a ``taskId`` is given return the If ``runId`` is 0 and a ``taskId`` is given return the