Move db insert into function in tsp/common.sh 99/88799/6
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 20 Sep 2016 11:37:41 +0000 (13:37 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 3 Jan 2017 15:13:57 +0000 (16:13 +0100)
lockfile-progs is now required for tl-master.
Access to database is now serialized.

Change-Id: I5d8de1da372ab4437a9ab885cb3a61dd0ef33d86
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
tsp/common.sh
tsp/jobs/publish.sh

index 18f8057..5c2dd95 100755 (executable)
@@ -73,3 +73,19 @@ project2sr() {
     test -n "$PROJECT_FILE" || die "Missing argument: project_file"
     head -n 1 "${PROJECT_FILE}" | tr -d '\n'
 }
+
+update_db() {
+    SR="$1"
+    TAG="$2"
+    BUILD_NR="$3"
+    TARGET="$4"
+    test -n "$SR" || die "Missing argument: sr"
+    test -n "$TAG" || die "Missing argument: tag"
+    test -n "$BUILD_NR" || die "Missing argument: build_nr"
+    test -n "$TARGET" || die "Missing argument: target"
+    lockfile-create --use-pid "${DBPATH}"
+    sqlite3 "${DBPATH}" "insert into test values (NULL,'$SR', CURRENT_TIMESTAMP, $BUILD_NR,\
+        (select r.rid from result r where r.rname='$TAG'),\
+        (select d.did from device d where d.dname='$TARGET'));"
+    lockfile-remove "${DBPATH}"
+}
index 2d6df1c..49417d3 100755 (executable)
@@ -154,9 +154,7 @@ echo "AVOCADO_TAG: $AVOCADO_TAG"
 echo "TARGET: $TARGET"
 
 # Publish to database
-sqlite3 "${DBPATH}" "insert into test values (NULL,'$SR', CURRENT_TIMESTAMP, $BUILD_NR,\
-    (select r.rid from result r where r.rname='$AVOCADO_TAG'),\
-    (select d.did from device d where d.dname='$TARGET'));"
+update_db "$SR" "$AVOCADO_TAG" "$BUILD_NR" "$TARGET"
 
 # Publish to www
 {