Handle SIGINT/SIGTERM, close database descriptior (fixes #5)

This commit is contained in:
Neil Alexander
2021-07-10 13:33:48 +01:00
parent c7b5325820
commit 2afb313061
2 changed files with 13 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ type SQLite3Storage struct {
*TableMailboxes
*TableMails
*TableQueue
db *sql.DB
writer *Writer
}
@@ -22,6 +23,7 @@ func NewSQLite3StorageStorage(filename string) (*SQLite3Storage, error) {
return nil, fmt.Errorf("sql.Open: %w", err)
}
s := &SQLite3Storage{
db: db,
writer: &Writer{
todo: make(chan writerTask),
},
@@ -45,6 +47,10 @@ func NewSQLite3StorageStorage(filename string) (*SQLite3Storage, error) {
return s, nil
}
func (s *SQLite3Storage) Close() error {
return s.db.Close()
}
type Writer struct {
running atomic.Bool
todo chan writerTask