diff --git a/src/mangadex/downloader.cr b/src/mangadex/downloader.cr index f335af2..793763d 100644 --- a/src/mangadex/downloader.cr +++ b/src/mangadex/downloader.cr @@ -27,14 +27,16 @@ module MangaDex def pop : Queue::Job? job = nil - DB.open "sqlite3://#{@queue.path}" do |db| - begin - db.query_one "select * from queue where id not like '%-%' " \ - "and (status = 0 or status = 1) " \ - "order by time limit 1" do |res| - job = Queue::Job.from_query_result res + MainFiber.run do + DB.open "sqlite3://#{@queue.path}" do |db| + begin + db.query_one "select * from queue where id not like '%-%' " \ + "and (status = 0 or status = 1) " \ + "order by time limit 1" do |res| + job = Queue::Job.from_query_result res + end + rescue end - rescue end end job diff --git a/src/plugin/downloader.cr b/src/plugin/downloader.cr index 4c23432..31d066d 100644 --- a/src/plugin/downloader.cr +++ b/src/plugin/downloader.cr @@ -8,14 +8,16 @@ class Plugin def pop : Queue::Job? job = nil - DB.open "sqlite3://#{@queue.path}" do |db| - begin - db.query_one "select * from queue where id like '%-%' " \ - "and (status = 0 or status = 1) " \ - "order by time limit 1" do |res| - job = Queue::Job.from_query_result res + MainFiber.run do + DB.open "sqlite3://#{@queue.path}" do |db| + begin + db.query_one "select * from queue where id like '%-%' " \ + "and (status = 0 or status = 1) " \ + "order by time limit 1" do |res| + job = Queue::Job.from_query_result res + end + rescue end - rescue end end job