Skip to content

Commit

Permalink
refactor: change deque logic
Browse files Browse the repository at this point in the history
  • Loading branch information
furkan-bilgin committed Oct 12, 2024
1 parent f6c69e6 commit bca6456
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
17 changes: 5 additions & 12 deletions src/daq/store/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,14 @@ def store_loop(self):
files_to_delete.append(file_path)
continue
writer = csv.writer(file.file)
rows_to_write = []

# Write rows in batches
rows_to_write.clear()
for _ in range(DAQ_JOB_STORE_CSV_WRITE_BATCH_SIZE):
try:
rows_to_write.append(file.write_queue.pop())
except IndexError:
break
if len(rows_to_write) > 0:
writer.writerows(rows_to_write)

row_size = len(file.write_queue)
if row_size > 0:
writer.writerows(list(file.write_queue))

# Flush if the flush time is up
if self._flush(file):
self._logger.debug(f"Flushed '{file.file.name}'")
self._logger.debug(f"Flushed '{file.file.name}' ({row_size} rows)")
for file_path in files_to_delete:
del self._open_csv_files[file_path]

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_store_loop_writerows(self, mock_csv_writer):
self.store.store_loop()

mock_writer_instance.writerows.assert_called_with(
[["row2_col1", "row2_col2"], ["row1_col1", "row1_col2"]]
[["row1_col1", "row1_col2"], ["row2_col1", "row2_col2"]]
)
self.assertTrue(file.file.flush.called)

Expand Down

0 comments on commit bca6456

Please sign in to comment.