From: Roman Bazalevsky Date: Thu, 23 Jan 2020 07:24:52 +0000 (+0300) Subject: Транзакционная работа с БД для избежания блокировок. X-Git-Url: https://git.rvb.name/weathermon.git/commitdiff_plain/21260a74f42a65603317d1938fac675d5eef6635?hp=--cc Транзакционная работа с БД для избежания блокировок. --- 21260a74f42a65603317d1938fac675d5eef6635 diff --git a/bin/dump-yesterday b/bin/dump-yesterday index d96d3dd..c9e1eaf 100755 --- a/bin/dump-yesterday +++ b/bin/dump-yesterday @@ -12,6 +12,6 @@ if [ -f "$logdb" ]; then /usr/bin/weather-filter $logdb dump-compacted $yesterday $dumpdir - sqlite3 $logdb "delete from log where time_stamp /dev/null || /etc/init.d/weather-display restart +pgrep weather-lcd > /dev/null || /etc/init.d/lcd-weather restart diff --git a/bin/weathermon b/bin/weathermon index bd9ca80..dbffa82 100755 --- a/bin/weathermon +++ b/bin/weathermon @@ -105,13 +105,17 @@ function submitValue(type,id,param,val) if code ~= 200 and backlog_con then printLog("writing record to backlog...") + backlog_con:execute('BEGIN TRANSACTION') backlog_con:execute(string.format("INSERT INTO queue(time_stamp,sensor_id,sensor,param,value) VALUES (datetime('now','localtime'),'%s','%s','%s',%f)",id,type,param,val)) + backlog_con:execute('COMMIT') end end if logdb then + log_con:execute('BEGIN TRANSACTION') log_con:execute(string.format("INSERT INTO log(time_stamp,sensor_id,sensor,param,value) VALUES (datetime('now','localtime'),'%s','%s','%s',%f)",id,type,param,val)) + log_con:execute('COMMIT') end end @@ -408,7 +412,6 @@ while 1 do io.close(f) end) end - end) end