avoid closing db handle when reconnecting to do a write

This commit is contained in:
Joey Hess 2015-02-22 14:21:39 -04:00
parent fd2a543c7d
commit e143d5e7d1

View file

@ -75,26 +75,20 @@ data Job
type TableName = String type TableName = String
workerThread :: T.Text -> TableName -> MVar Job -> IO () workerThread :: T.Text -> TableName -> MVar Job -> IO ()
workerThread db tablename jobs = catchNonAsync loop showerr workerThread db tablename jobs = catchNonAsync (run loop) showerr
where where
showerr e = liftIO $ warningIO $ showerr e = liftIO $ warningIO $
"sqlite worker thread crashed: " ++ show e "sqlite worker thread crashed: " ++ show e
loop = do loop = do
r <- run queryloop job <- liftIO $ takeMVar jobs
case r of case job of
QueryJob _ -> loop QueryJob a -> a >> loop
-- change is run in a separate database connection -- change is run in a separate database connection
-- since sqlite only supports a single writer at a -- since sqlite only supports a single writer at a
-- time, and it may crash the database connection -- time, and it may crash the database connection
ChangeJob a -> a run >> loop ChangeJob a -> liftIO (a run) >> loop
CloseJob -> return () CloseJob -> return ()
queryloop = do
job <- liftIO $ takeMVar jobs
case job of
QueryJob a -> a >> queryloop
_ -> return job
-- like runSqlite, but calls settle on the raw sql Connection. -- like runSqlite, but calls settle on the raw sql Connection.
run a = do run a = do