Skip to content

Commit

Permalink
A sqlite close
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenorzz committed Mar 28, 2022
1 parent eddfb49 commit c923975
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func main() {
fmt.Printf("Task shutdown failed, err: %s\n", err.Error())
}
println("Task shutdown gracefully")

println("SQLite is trying to shutdown, wait for a minute")
if err := model.Shutdown(); err != nil {
fmt.Printf("SQLite shutdown failed, err: %s\n", err.Error())
}
println("SQLite shutdown gracefully")
}()
if config.Toml.Web.Port != "" {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
Expand Down
4 changes: 4 additions & 0 deletions model/Model.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func Init() {
core.Log(core.INFO, fmt.Sprintf("server id %d", goployServerID))
}

func Shutdown() error {
return DB.Close()
}

func createTable() error {
conn := DB.Get(nil)
defer DB.Put(conn)
Expand Down

0 comments on commit c923975

Please sign in to comment.