浏览代码

fix #60 - sqlite lock + badges (#61)

* don't fatal is DB is locked + Fix #60
Thibault "bui" Koechlin 5 年之前
父节点
当前提交
f9a4ae2b3f
共有 2 个文件被更改,包括 5 次插入1 次删除
  1. 2 0
      README.md
  2. 3 1
      pkg/sqlite/commit.go

+ 2 - 0
README.md

@@ -10,6 +10,8 @@
 <p align="center">
 <img src="https://github.com/crowdsecurity/crowdsec/workflows/Go/badge.svg">
 <img src="https://github.com/crowdsecurity/crowdsec/workflows/build-binary-package/badge.svg">
+<img src="https://goreportcard.com/badge/github.com/crowdsecurity/crowdsec">
+<img src="https://img.shields.io/github/license/crowdsecurity/crowdsec">
 </p>
 
 <p align="center">

+ 3 - 1
pkg/sqlite/commit.go

@@ -14,7 +14,9 @@ func (c *Context) Flush() error {
 	defer c.lock.Unlock()
 
 	ret := c.tx.Commit()
+
 	if ret.Error != nil {
+		c.tx = c.Db.Begin()
 		return fmt.Errorf("failed to commit records : %v", ret.Error)
 	}
 	c.tx = c.Db.Begin()
@@ -37,7 +39,7 @@ func (c *Context) AutoCommit() {
 			if atomic.LoadInt32(&c.count) != 0 &&
 				(atomic.LoadInt32(&c.count)%100 == 0 || time.Since(c.lastCommit) >= 500*time.Millisecond) {
 				if err := c.Flush(); err != nil {
-					log.Fatalf("failed to flush : %s", err)
+					log.Errorf("failed to flush : %s", err)
 				}
 			}
 		}