Skip to content

Commit fa6dd38

Browse files
committed
Don't forget to report fileset complete even if there is an exception
1 parent 40752b5 commit fa6dd38

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

src/servicex_did_finder_lib/did_finder_app.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,23 @@ def do_lookup(self, did: str, dataset_id: int, endpoint: str, user_did_finder: U
9999
for file_info in user_did_finder(did_info.did, info, self.app.did_finder_args):
100100
acc.add(file_info)
101101

102-
except Exception:
103-
if did_info.get_mode == "all":
104-
raise
105-
106-
acc.send_on(did_info.file_count)
107-
108-
elapsed_time = int((datetime.now() - start_time).total_seconds())
109-
servicex.put_fileset_complete(
110-
{
111-
"files": summary.file_count,
112-
"files-skipped": summary.files_skipped,
113-
"total-events": summary.total_events,
114-
"total-bytes": summary.total_bytes,
115-
"elapsed-time": elapsed_time,
116-
}
117-
)
102+
acc.send_on(did_info.file_count)
103+
except Exception as e:
104+
self.logger.error(
105+
f"Error processing DID {did}: {e}",
106+
extra={"dataset_id": dataset_id}
107+
)
108+
finally:
109+
elapsed_time = int((datetime.now() - start_time).total_seconds())
110+
servicex.put_fileset_complete(
111+
{
112+
"files": summary.file_count,
113+
"files-skipped": summary.files_skipped,
114+
"total-events": summary.total_events,
115+
"total-bytes": summary.total_bytes,
116+
"elapsed-time": elapsed_time,
117+
}
118+
)
118119

119120

120121
class DIDFinderApp:

tests/servicex_did_finder_lib_tests/test_did_finder_app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,35 @@ def test_did_finder_task(mocker, servicex, single_file_info):
7575
)
7676

7777

78+
def test_did_finder_task_exception(mocker, servicex, single_file_info):
79+
did_finder_task = DIDFinderTask()
80+
# did_finder_task.app = mocker.Mock()
81+
did_finder_task.app.did_finder_args = {}
82+
mock_generator = mocker.Mock(side_effect=Exception("Boom"))
83+
84+
mock_accumulator = mocker.MagicMock(Accumulator)
85+
with patch(
86+
"servicex_did_finder_lib.did_finder_app.Accumulator", autospec=True
87+
) as acc:
88+
acc.return_value = mock_accumulator
89+
did_finder_task.do_lookup('did', 1, 'https://my-servicex', mock_generator)
90+
servicex.assert_called_with(dataset_id=1, endpoint="https://my-servicex")
91+
acc.assert_called_once()
92+
93+
mock_accumulator.add.assert_not_called()
94+
mock_accumulator.send_on.assert_not_called()
95+
96+
servicex.return_value.put_fileset_complete.assert_called_with(
97+
{
98+
"files": 0, # Aught to have a side effect in mock accumulator that updates this
99+
"files-skipped": 0,
100+
"total-events": 0,
101+
"total-bytes": 0,
102+
"elapsed-time": 0,
103+
}
104+
)
105+
106+
78107
def test_did_finder_app(mocker, monkeypatch):
79108
# Temporarily replace sys.argv with mock_args
80109
monkeypatch.setattr(sys, 'argv', [

0 commit comments

Comments
 (0)