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

* don't fatal is DB is locked + Fix #60
This commit is contained in:
Thibault "bui" Koechlin 2020-06-03 14:18:00 +02:00 committed by GitHub
parent a58df696cf
commit f9a4ae2b3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -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">

View file

@ -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)
}
}
}