Skip to content

Commit

Permalink
fix: fixed a bug that made csv daqjob write headers even if file exis…
Browse files Browse the repository at this point in the history
…ted before
  • Loading branch information
furkan-bilgin committed Oct 11, 2024
1 parent d105ee9 commit 8f7214f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/daq/store/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ def handle_message(self, message: DAQJobMessageStore) -> bool:
)

if file_path not in self._open_files:
file_exists = os.path.exists(file_path)
# Create the file if it doesn't exist
Path(file_path).touch(exist_ok=True)
if not file_exists:
Path(file_path).touch()

# Open file and write csv headers
file = open(file_path, "a")
self._open_files[file_path] = file
writer = csv.writer(file)
writer.writerow(message.keys)

# Write headers if file haven't existed before
if not file_exists:
writer.writerow(message.keys)
else:
file = self._open_files[file_path]
writer = csv.writer(file)
Expand Down

0 comments on commit 8f7214f

Please sign in to comment.