This is my first question on stackoverflow ????.
Background: From the reference for appendRow(rowContents) I understand that this operation is atomic, meaning that concurrent access to the last row of a sheet is handled and potential issues are prevented.
Issue / Unexpected Behavior:
However, I recently realised that with many concurrent instances of a function that is appending rows to the very same sheet, the last row regularly is overwritten with the fresh data from appendRow(rowContents)
, instead of rowContents
being appended as a new row below the last row.
In the past, I did not experience issues with appendRow()
overwriting content on a sheet. It seems to be a recent phenomenon. However, this is my first GAS project that has so many concurrent instances logging their progress to the same spreadsheet/sheet.
Goal to be achieved: Independent from the number of concurrent instances, the script should append one row for each appendRow() operation rather than overwriting previous rows.
Small sample that reproduces the problem:
- See it in action → Screen Recording
- Code / Google Apps Script project file → included in the google spreadsheet
What I have already tried:
- Instead of logging to the spreadsheet, I've sent an email for each
appendRow()
operation. I can confirm that this is working as expected (I received an email for everyappendRow()
operation) - Make use of Lock Service: As long as the timeout for trying to acquire a lock is not reached, each
appendRow()
operation generates a new row. As soon as the timeout is reached,appendRow()
starts overwriting the last row again.
Call for help:
- Is anybody facing the same issue?
- What workarounds do you suggest?
- Am I missing something completely? ????
Any thoughts are highly appreciated! ????