Skip to content

Commit 8c66738

Browse files
committed
Ignore duplicate log entries
Before an entry is appended, match for duplicate and ignore if there is a match.
1 parent 4f2ca58 commit 8c66738

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

orquesta/conducting.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,21 @@ def log_entry(self, entry_type, message,
229229
if entry_type not in ['info', 'warn', 'error']:
230230
raise exc.WorkflowLogEntryError('The log entry type "%s" is not valid.' % entry_type)
231231

232-
# Create a log entry.
232+
# Identify the appropriate log and then log the entry.
233+
log = self.errors if entry_type == 'error' else self.log
234+
235+
# Create the log entry.
233236
entry = {'type': entry_type, 'message': message}
234237
dx.set_dict_value(entry, 'task_id', task_id, insert_null=False)
235238
dx.set_dict_value(entry, 'task_transition_id', task_transition_id, insert_null=False)
236239
dx.set_dict_value(entry, 'result', result, insert_null=False)
237240
dx.set_dict_value(entry, 'data', data, insert_null=False)
238241

239-
# Identify the appropriate log and then log the entry.
240-
log = self.errors if entry_type == 'error' else self.log
242+
# Ignore if this is a duplicate.
243+
if len(list(filter(lambda x: x == entry, log))) > 0:
244+
return
245+
246+
# Append the log entry.
241247
log.append(entry)
242248

243249
def log_error(self, e, task_id=None, task_transition_id=None):

orquesta/tests/unit/conducting/test_workflow_conductor.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def test_set_workflow_paused_when_has_active_tasks(self):
749749
conductor.request_workflow_state(states.PAUSED)
750750
self.assertEqual(conductor.get_workflow_state(), states.PAUSING)
751751

752-
def test_append_log_entry(self):
752+
def test_append_log_entries(self):
753753
inputs = {'a': 123, 'b': True}
754754
conductor = self._prep_conductor(inputs=inputs, state=states.RUNNING)
755755

@@ -838,3 +838,58 @@ def test_append_log_entry(self):
838838
self.assertIsInstance(conductor.flow, conducting.TaskFlow)
839839
self.assertListEqual(conductor.log, expected_log_entries)
840840
self.assertListEqual(conductor.errors, expected_errors)
841+
842+
def test_append_duplicate_log_entries(self):
843+
inputs = {'a': 123, 'b': True}
844+
conductor = self._prep_conductor(inputs=inputs, state=states.RUNNING)
845+
846+
extra = {'x': 1234}
847+
conductor.log_entry('info', 'The workflow is running as expected.', data=extra)
848+
conductor.log_entry('info', 'The workflow is running as expected.', data=extra)
849+
conductor.log_entry('warn', 'The task may be running a little bit slow.', task_id='task1')
850+
conductor.log_entry('warn', 'The task may be running a little bit slow.', task_id='task1')
851+
conductor.log_entry('error', 'This is baloney.', task_id='task1')
852+
conductor.log_entry('error', 'This is baloney.', task_id='task1')
853+
conductor.log_error(TypeError('Something is not right.'), task_id='task1')
854+
conductor.log_error(TypeError('Something is not right.'), task_id='task1')
855+
conductor.log_errors([KeyError('task1'), ValueError('foobar')], task_id='task1')
856+
conductor.log_errors([KeyError('task1'), ValueError('foobar')], task_id='task1')
857+
858+
expected_log_entries = [
859+
{
860+
'type': 'info',
861+
'message': 'The workflow is running as expected.',
862+
'data': extra
863+
},
864+
{
865+
'type': 'warn',
866+
'message': 'The task may be running a little bit slow.',
867+
'task_id': 'task1'
868+
}
869+
]
870+
871+
expected_errors = [
872+
{
873+
'type': 'error',
874+
'message': 'This is baloney.',
875+
'task_id': 'task1'
876+
},
877+
{
878+
'type': 'error',
879+
'message': 'TypeError: Something is not right.',
880+
'task_id': 'task1'
881+
},
882+
{
883+
'type': 'error',
884+
'message': "KeyError: 'task1'",
885+
'task_id': 'task1'
886+
},
887+
{
888+
'type': 'error',
889+
'message': 'ValueError: foobar',
890+
'task_id': 'task1'
891+
}
892+
]
893+
894+
self.assertListEqual(conductor.log, expected_log_entries)
895+
self.assertListEqual(conductor.errors, expected_errors)

0 commit comments

Comments
 (0)