From b75a838e144c7e545aa2afa8939a0414a3f0cffe Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Tue, 21 Jul 2020 12:32:48 +0000 Subject: [PATCH] Move common code to Queue::Downloader --- src/mangadex/downloader.cr | 6 +----- src/plugin/downloader.cr | 5 +---- src/queue.cr | 8 ++++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mangadex/downloader.cr b/src/mangadex/downloader.cr index 5c43437..9b0f232 100644 --- a/src/mangadex/downloader.cr +++ b/src/mangadex/downloader.cr @@ -3,12 +3,9 @@ require "zip" module MangaDex class Downloader < Queue::Downloader - property stopped = false @wait_seconds : Int32 = Config.current.mangadex["download_wait_seconds"] .to_i32 @retries : Int32 = Config.current.mangadex["download_retries"].to_i32 - @library_path : String = Config.current.library_path - @downloading = false def self.default : self unless @@default @@ -18,9 +15,8 @@ module MangaDex end def initialize - @queue = Queue.default + super @api = API.default - @queue << self spawn do loop do diff --git a/src/plugin/downloader.cr b/src/plugin/downloader.cr index 8726f7d..9b55fd4 100644 --- a/src/plugin/downloader.cr +++ b/src/plugin/downloader.cr @@ -1,7 +1,5 @@ class Plugin class Downloader < Queue::Downloader - @library_path : String = Config.current.library_path - @downloading = false def self.default : self unless @@default @@ -11,8 +9,7 @@ class Plugin end def initialize - @queue = Queue.default - @queue << self + super end end end diff --git a/src/queue.cr b/src/queue.cr index b1e1613..3235fc3 100644 --- a/src/queue.cr +++ b/src/queue.cr @@ -1,8 +1,16 @@ require "sqlite3" +require "./util/*" class Queue class Downloader property stopped = false + @library_path : String = Config.current.library_path + @downloading = false + + def initialize + @queue = Queue.default + @queue << self + end end class PageJob