Move pop to the Downloader classes

This commit is contained in:
Alex Ling
2020-07-21 17:20:03 +00:00
parent 2a36804e8d
commit 92f5a90629
3 changed files with 35 additions and 19 deletions

View File

@@ -18,7 +18,7 @@ module MangaDex
sleep 1.second
next if @stopped || @downloading
begin
job = @queue.pop
job = pop
next if job.nil?
download job
rescue e
@@ -28,6 +28,21 @@ module MangaDex
end
end
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
end
rescue
end
end
job
end
private def download(job : Queue::Job)
@downloading = true
@queue.set_status Queue::JobStatus::Downloading, job