07.08.2023, 08:22
You can create a scheduled script to write data to CSV and use storage lists for storing temporary entries. This will solve the issue with writing in parallel.
This code adds an entry to the end of the list named mylist. Note that the value can only be a string, but not a Lua table.
This code reads all entries from the list named mylist. All read entries are removed. New entries entries that can be added when the script is already running are not affected.
This code adds an entry to the end of the list named mylist. Note that the value can only be a string, but not a Lua table.
Code:
key = 'mylist'
value = 'some string value'
storage.exec('rpush', key, value)
This code reads all entries from the list named mylist. All read entries are removed. New entries entries that can be added when the script is already running are not affected.
Code:
key = 'mylist'
values = storage.exec('lrange', key, 0, -1)
if type(values) == 'table' then
for _, value in ipairs(values) do
-- do something with value
end
-- remove read entries from the list
storage.exec('ltrim', key, #values, -1)
end