Commit fd8a1cdf authored by Philippe Pepiot's avatar Philippe Pepiot
Browse files

[entities] use try/except to get or create CeleryTask

IMHO this looks better than "if rset".
Also log created entity eid.
parent 511c159acb12
...@@ -273,15 +273,15 @@ class CeleryTaskAdapter(ICeleryTask): ...@@ -273,15 +273,15 @@ class CeleryTaskAdapter(ICeleryTask):
for asr in tree(result): for asr in tree(result):
task_id = six.text_type(asr.id) task_id = six.text_type(asr.id)
rset = self._cw.find('CeleryTask', task_id=task_id) try:
if rset: cwtask = self._cw.find('CeleryTask', task_id=task_id).one()
cwtask = rset.one() except NoResultError:
else:
self.info("create a CeleryTask for %s" % task_id)
cwtask = self._cw.create_entity( cwtask = self._cw.create_entity(
'CeleryTask', 'CeleryTask',
task_name=UNKNOWN_TASK_NAME, task_name=UNKNOWN_TASK_NAME,
task_id=six.text_type(task_id)) task_id=six.text_type(task_id))
self.info("Create <CeleryTask %s (task_id %s)>",
cwtask.eid, task_id)
if not cwtask.parent_task and self.entity is not cwtask: if not cwtask.parent_task and self.entity is not cwtask:
self.info('Set %s parent_task to %s (%s)', cwtask.task_id, self.info('Set %s parent_task to %s (%s)', cwtask.task_id,
self.entity, self.entity.task_id) self.entity, self.entity.task_id)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment