Skip to content
Snippets Groups Projects
Commit d206d455 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Log task-related session events

parent 260f9c3a
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,7 @@ class TaskCollection(object): ...@@ -60,6 +60,7 @@ class TaskCollection(object):
} }
self._handles[task_id] = func self._handles[task_id] = func
logger.info(f'Added task {task_id}: {str(func)}')
return str(task_id) return str(task_id)
...@@ -84,14 +85,17 @@ class TaskCollection(object): ...@@ -84,14 +85,17 @@ class TaskCollection(object):
f = self._handles[task_id] f = self._handles[task_id]
p = task['params'] p = task['params']
try: try:
logger.info(f'Started running task {task_id}')
task['status'] = self.status_codes['in_progress'] task['status'] = self.status_codes['in_progress']
result = f(p) result = f(p)
logger.info(f'Finished running task {task_id}')
task['status'] = self.status_codes['finished'] task['status'] = self.status_codes['finished']
task['result'] = result task['result'] = result
return result return result
except Exception as e: except Exception as e:
task['status'] = self.status_codes['failed'] task['status'] = self.status_codes['failed']
task['error'] = str(e) task['error'] = str(e)
logger.error(f'Error running task {task_id}: {str(e)}')
raise RunTaskError(e) raise RunTaskError(e)
class _Session(object): class _Session(object):
...@@ -160,6 +164,7 @@ class _Session(object): ...@@ -160,6 +164,7 @@ class _Session(object):
idx = len(self.accessors) idx = len(self.accessors)
accessor_id = f'acc_{idx:06d}' accessor_id = f'acc_{idx:06d}'
self.accessors[accessor_id] = {'loaded': True, 'object': acc, **acc.info} self.accessors[accessor_id] = {'loaded': True, 'object': acc, **acc.info}
self.log_info(f'Added accessor {accessor_id}')
return accessor_id return accessor_id
def del_accessor(self, accessor_id: str) -> str: def del_accessor(self, accessor_id: str) -> str:
...@@ -177,6 +182,7 @@ class _Session(object): ...@@ -177,6 +182,7 @@ class _Session(object):
assert isinstance(v['object'], GenericImageDataAccessor) assert isinstance(v['object'], GenericImageDataAccessor)
v['loaded'] = False v['loaded'] = False
v['object'] = None v['object'] = None
self.log_info(f'Deleted accessor {accessor_id}')
return accessor_id return accessor_id
def del_all_accessors(self) -> list[str]: def del_all_accessors(self) -> list[str]:
...@@ -190,6 +196,7 @@ class _Session(object): ...@@ -190,6 +196,7 @@ class _Session(object):
v['object'] = None v['object'] = None
v['loaded'] = False v['loaded'] = False
res.append(k) res.append(k)
self.log_info(f'Deleted accessor {k}')
return res return res
...@@ -224,11 +231,12 @@ class _Session(object): ...@@ -224,11 +231,12 @@ class _Session(object):
self.del_accessor(acc_id) self.del_accessor(acc_id)
return acc return acc
def write_accessor(self, acc_id: str, filename: Union[str, None] = None, pop=True) -> str: def write_accessor(self, acc_id: str, filename: Union[str, None] = None, pop: bool = True) -> str:
""" """
Write an accessor to file and unload it from the session Write an accessor to file and optionally unload it from the session
:param acc_id: accessor's ID :param acc_id: accessor's ID
:param filename: force use of a specific filename, raise InvalidPathError if this already exists :param filename: force use of a specific filename, raise InvalidPathError if this already exists
:param pop: unload accessor from the session if True
:return: name of file :return: name of file
""" """
if filename is None: if filename is None:
...@@ -250,6 +258,7 @@ class _Session(object): ...@@ -250,6 +258,7 @@ class _Session(object):
else: else:
acc.write(fp) acc.write(fp)
self.accessors[acc_id]['filepath'] = fp.__str__() self.accessors[acc_id]['filepath'] = fp.__str__()
self.log_info(f'Wrote accessor {acc_id} to {fp.__str__()}')
return fp.name return fp.name
def add_roiset(self, roiset: RoiSet, roiset_id: str = None) -> str: def add_roiset(self, roiset: RoiSet, roiset_id: str = None) -> str:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment