event_next_task_update is not launched on creating/deleting entity

This commit is contained in:
Jakub Trllo 2019-03-13 16:33:01 +01:00
parent b653200a8b
commit a613476f53

View file

@ -42,41 +42,47 @@ class NextTaskUpdate(BaseEvent):
for entity in event['data'].get('entities', []):
if (entity['entityType'] == 'task' and
'statusid' in entity['keys']):
statusid_changes = entity.get('changes', {}).get('statusid', {})
if (
entity['entityType'] != 'task' or
'statusid' not in entity['keys'] or
statusid_changes.get('new', None) is None or
statusid_changes.get('old', None) is None
):
continue
task = session.get('Task', entity['entityId'])
task = session.get('Task', entity['entityId'])
status = session.get('Status',
entity['changes']['statusid']['new'])
state = status['state']['name']
status = session.get('Status',
entity['changes']['statusid']['new'])
state = status['state']['name']
next_task = self.get_next_task(task, session)
next_task = self.get_next_task(task, session)
# Setting next task to Ready, if on NOT READY
if next_task and state == 'Done':
if next_task['status']['name'].lower() == 'not ready':
# Setting next task to Ready, if on NOT READY
if next_task and state == 'Done':
if next_task['status']['name'].lower() == 'not ready':
# Get path to task
path = task['name']
for p in task['ancestors']:
path = p['name'] + '/' + path
# Get path to task
path = task['name']
for p in task['ancestors']:
path = p['name'] + '/' + path
# Setting next task status
try:
query = 'Status where name is "{}"'.format('Ready')
status_to_set = session.query(query).one()
next_task['status'] = status_to_set
except Exception as e:
self.log.warning((
'!!! [ {} ] status couldnt be set: [ {} ]'
).format(path, e))
else:
self.log.info((
'>>> [ {} ] updated to [ Ready ]'
).format(path))
# Setting next task status
try:
query = 'Status where name is "{}"'.format('Ready')
status_to_set = session.query(query).one()
next_task['status'] = status_to_set
except Exception as e:
self.log.warning((
'!!! [ {} ] status couldnt be set: [ {} ]'
).format(path, e))
else:
self.log.info((
'>>> [ {} ] updated to [ Ready ]'
).format(path))
session.commit()
session.commit()
def register(session, **kw):
'''Register plugin. Called when used as an plugin.'''